modulepackage
1.7.3
Repository: https://github.com/dedalqq/omg.httpserver.git
Documentation: pkg.go.dev
# README
omg.httpServer
omg.httpServer is the simple http handler for a standard http server. Also, its library contains the router for manage http requests. This library is best for creating API based on http request.
Example
package main
import (
"context"
"net/http"
httpserver "github.com/dedalqq/omg.httpserver"
)
type Container struct{}
type AuthInfo struct{}
type UserRequest struct {
UserID string `args:"user-id"`
}
type UserResponse struct{}
func main() {
r := httpserver.NewRouter[*Container, *AuthInfo]()
sr := r.SubRoute("/api/v1")
sr.Add("/user/{user-id}", httpserver.Handler[*Container, *AuthInfo]{
Get: httpserver.Create(func(ctx context.Context, c *Container, a *AuthInfo, rq *UserRequest) (*UserResponse, error) {
return &UserResponse{}, nil
}),
})
r.AddSwaggerSubRoute("/swagger.json", sr, httpserver.SwaggerOpt{})
h := httpserver.NewHttpHandler(r, httpserver.Options{})
h.SetAuthFunc(func(request *http.Request) (*AuthInfo, error) {
return &AuthInfo{}, nil
})
server := &http.Server{
Addr: ":80",
Handler: h,
}
server.ListenAndServe()
}
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewRouter creates and returns new router.
NewServer creates and return new http server which the contains omg http handler.
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Options for omg http handlers.
No description provided by the author
Router is a router object.
SubRouter is a sub router object.
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author