Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/luisvinicius167/godux
State Management for Go Backend applications inspired by Redux.
╔═════════╗ ╔══════════╗ ╔═══════════╗ ╔═════════════════╗ ║ Action ║──────>║ Reducer ║ ────> ║ Store ║ ────> ║ Application ║ ╚═════════╝ ╚══════════╝ ╚═══════════╝ ╚═════════════════╝ ^ │ └────────────────────────────────────────────────────────────┘
go get github.com/luisvinicius167/godux
godux gives go unidirectional data flow:
A Store is basically a container that holds your application state.
store := godux.NewStore()
store.Setstate("count", 1)
store.Setstate("Title", "I like godux!")
Actions are just pure functions which pass on their inputs when they're dispatched. Actions are stored on the godux
map as godux.Action
.
increment := func(number int) godux.Action {
return godux.Action{
Type: "INCREMENT",
Value: number,
}
}
As in Redux:
"Actions describe the fact that something happened, but don’t specify how the application’s state changes in response. This is the job of a reducer".
Reducers are pure functions that take in actions and the state of the store as inputs and leave them all as they came in (aka. pure)-- especially the original state of the store must not be modified (it's accessed by store.GetState
)).
// reducer function
reducer := func(action godux.Action) interface{} {
switch action.Type {
case "INCREMENT":
return store.GetState("count").(int) + action.Value.(int)
case "DECREMENT":
return action.Value.(int) - store.GetState("count").(int)
default:
return store.GetAllState()
}
}
// Add your reducer function to return new values basend on your state
store.Reducer(reducer)
Dispatching an action is very easy.
// Receive new value
newCount := store.Dispatch(increment(1)) // return 2
godux.newStore()
: Create a single store with the state of your application (should only be used once).godux.SetState(name string, value interface{})
: Sets the state of the store.godux.GetState(name string)
: Return a state's value.godux.GetAllState()
: Return the whole state as a map.store.Reducer(func(action godux.Action))
: Adding a reducer function to your Store.store.Dispatch(action godux.Action)
: Dispatching an action to your Reducer.godux.Action( Type string, Value interface{})
: Adding an easily available Action.MIT License.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.