web

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 13 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(s *ServerOptions)

Option the function to apply configuration option

func RegisterMiddleware added in v0.0.3

func RegisterMiddleware(middleware handler.Middleware) Option

RegisterMiddleware inject a handler to server,then can be used in Server.Apply method

func RegisterMiddlewareByFunc added in v0.0.3

func RegisterMiddlewareByFunc(name string, handlerFunc handler.MiddlewareApplyFunc) Option

RegisterMiddlewareByFunc provide a simple way to inject a middleware by gin.HandlerFunc.

Notice: the middleware usual attach `c.Next()` or `c.Abort` to indicator whether exits the method. example:

RegisterMiddlewareByFunc("test",func(c *gin.Context) {
        ....process
        c.Next() or c.Abort() or c.AbortWithStatus(500)
    }

)

func WithConfiguration added in v0.1.0

func WithConfiguration(cfg *conf.Configuration) Option

WithConfiguration set up the configuration of the web server by a configuration instance

func WithGracefulStop added in v0.1.0

func WithGracefulStop() Option

WithGracefulStop indicate use graceful stop

type Router

type Router struct {
	*gin.Engine
	Groups []*RouterGroup

	AfterRegisterInternalHandler func(*Router)
	// contains filtered or unexported fields
}

Router is base on Gin you can use AfterRegisterInternalHandler to replace an inline HandlerFunc or add a new

func NewRouter

func NewRouter(options *ServerOptions) *Router

func (*Router) Apply

func (r *Router) Apply(cnf *conf.Configuration) (err error)

func (*Router) FindGroup added in v0.0.3

func (r *Router) FindGroup(basePath string) *RouterGroup

FindGroup return a specified router group by an url format base path.

parameter basePath is map to configuration:

routerGroups:
- group:
  basePath: "/auth"

type RouterGroup added in v0.0.3

type RouterGroup struct {
	Group *gin.RouterGroup

	Router *Router
	// contains filtered or unexported fields
}

RouterGroup is a wrapper for gin.RouterGroup.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Server

New create a web server

func (*Server) Apply

func (s *Server) Apply(cfg *conf.Configuration)

func (*Server) HandlerManager added in v0.0.3

func (s *Server) HandlerManager() *handler.Manager

HandlerManager return server's handler manager,it's convenient to process handler

func (*Server) ListenAndServe added in v0.0.3

func (s *Server) ListenAndServe() (err error)

ListenAndServe Starts Http Server

return

http.ErrServerClosed or other error

func (*Server) Router

func (s *Server) Router() *Router

func (*Server) Run

func (s *Server) Run() error

Run builtin run the server.

you can process whole yourself

func (*Server) ServerOptions added in v0.0.3

func (s *Server) ServerOptions() ServerOptions

ServerOptions return a setting used by web server

func (*Server) Start added in v0.1.0

func (s *Server) Start(ctx context.Context) error

func (*Server) Stop added in v0.0.3

func (s *Server) Stop(ctx context.Context) error

Stop http server and clear resource

type ServerOptions added in v0.0.3

type ServerOptions struct {
	Addr string    `json:"addr" yaml:"addr"`
	TLS  *conf.TLS `json:"tls" yaml:"tls"`
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL