Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"log"
"net/http"
"github.com/lancer-kit/uwe/v3"
)
func main() {
// fill configurations for the predefined worker that start an HTTP server
apiCfg := Config{
Host: "0.0.0.0",
Port: 8080,
EnableCORS: false,
APIRequestTimeout: 0,
}
// initialize new instance of Chief
chief := uwe.NewChief()
chief.SetEventHandler(uwe.STDLogEventHandler())
// will add workers into the pool
chief.AddWorker("app-server", NewServer(apiCfg, getRouter()))
// init all registered workers and run it all
chief.Run()
}
// getRouter is used to declare an API scheme,
func getRouter() http.Handler {
// instead default can be used any another compatible router
mux := http.NewServeMux()
mux.HandleFunc("/hello/uwe", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintln(w, "hello world")
})
log.Println("REST API router initialized")
return mux
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Host string `json:"host" yaml:"host" toml:"host"`
Port int `json:"port" yaml:"port" toml:"port"`
EnableCORS bool `json:"enable_cors" yaml:"enable_cors" toml:"enable_cors"`
// nolint:lll
APIRequestTimeout int `json:"api_request_timeout" yaml:"api_request_timeout" toml:"api_request_timeout"`
ReadHeaderTimeout int `json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout"`
}
Config is a parameters for `http.Server`. APIRequestTimeout and ReadHeaderTimeout time.Duration in Seconds.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is worker by default for starting a standard HTTP server. Server requires configuration and filled `http.Handler`. The HTTP server will work properly and will be correctly disconnected upon a signal from Supervisor (Chief). Warning: this Server does not process SSL/TLS certificates on its own.
To start an HTTPS server, look for a specific worker.
func NewServer ¶
NewServer returns a new instance of `Server` with the passed configuration and HTTP router.
func NewServerWithInitFunc ¶
func NewServerWithInitFunc(config Config, routerInit func(ctx uwe.Context) (http.Handler, error)) *Server
NewServerWithInitFunc returns a new instance of `Server` with the passed configuration. Server router will be initialized during the call of Run() method. This allows to pass and use uwe.Context in handlers, e.g. to use imq and Mailbox.