
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
github.com/aliforever/go-generichandler
A simple json event handler using generics made to save hours of my life in tens of projects
go get -u github.com/aliforever/go-generichandler
package main
import (
"fmt"
"github.com/aliforever/go-generichandler"
"time"
)
type ping struct {
Time time.Time `json:"time"`
}
func PingHandler(p ping) error {
fmt.Println(p.Time)
return nil
}
func main() {
handlers := generichandler.NewHandlers()
handlers.AddHandler("ping", generichandler.Handler[ping](PingHandler))
event := []byte(fmt.Sprintf(`{"time": "%s"}`, time.Now().Format(time.RFC3339)))
err := handlers.Handle("ping", event)
if err != nil {
panic(err)
}
}
Basically I follow a convention in my projects, each handler has an input of type []byte (json.RawMessage).
With this package we remove the need to decode json types inside handler functions to their specific type
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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.