Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

middleware

Small collection of reusable Go middleware.

Packages

  • github.com/salivare-io/middleware/chi - chi middlewares for logging and bearer auth.

chi

Logger

Adds request logging with slogx and keeps request ID in the logger context (compatible with chi's middleware.RequestID).

r := chi.NewRouter()
log := slogx.New(slog.NewJSONHandler(os.Stdout, nil))

r.Use(chimw.RequestID)
r.Use(rpcmiddleware.LoggerContext(log))
r.Use(rpcmiddleware.Logger(log))

Bearer

Validates Authorization: Bearer <token> using a minimal interface to avoid hard dependencies.

type AppManager struct{}

func (m *AppManager) VerifyBearerToken(ctx context.Context, token string) (string, error) {
	// ...
	return "app-id", nil
}

r.Use(rpcmiddleware.Bearer(&AppManager{}))

The middleware stores two values in context:

  • auth marker: rpcmiddleware.FromContext(ctx)
  • app ID: rpcmiddleware.GetAppIDFromContext(ctx)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors