
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
github.com/husobee/backdrop
Context is critical for web applications. Many frameworks solve the context issue by locking you into their framework. This project attempts to provide a clean interface to use net.context within your framework agnostic application.
package main
import (
"fmt"
"net/http"
"time"
"golang.org/x/net/context"
"github.com/codegangsta/negroni"
"github.com/husobee/backdrop"
"github.com/husobee/vestigo"
"github.com/satori/go.uuid"
"github.com/tylerb/graceful"
)
func main() {
// using negroni for this example to show middlewares can access context
n := negroni.Classic()
// start backdrop - here you can provide a backdrop.Options with a base
// context to inherit from if you choose.
backdrop.Start(nil)
// set up awesome router ;)
router := vestigo.NewRouter()
router.Get("/:name", f)
n.Use(&ridMiddleware{})
// add router to middleware
n.UseHandler(router)
// graceful start/stop server
srv := &graceful.Server{
Timeout: 5 * time.Second,
Server: &http.Server{
Addr: ":1234",
// top level handler needs to clear the context
// per each request, use this wrapper handler
Handler: backdrop.NewClearContextHandler(n),
},
}
srv.ListenAndServe()
}
func f(w http.ResponseWriter, r *http.Request) {
// get the id from the context
id, err := backdrop.Get(r, "id")
if err != nil {
fmt.Println("err: ", err.Error())
}
fmt.Printf("request id is: %v\n", id)
// you can also get the entire context if you are more comfortable with that
ctx := backdrop.GetContext(r)
ctx = context.WithValue(ctx, "key", "value")
// and setting the newly created context in backdrop
backdrop.SetContext(r, ctx)
}
type ridMiddleware struct{}
func (rid *ridMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
// example of setting a value to the context
backdrop.Set(r, "id", uuid.NewV4())
next(w, r)
}
If you wish to contribute, please fork this repository, submit an issue, or pull request with your suggestions.
Please use gofmt and golint before trying to contribute.
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.