- Pkg HTTP Server : add config option to disabled a server

- Pkg HTTP Server : add option to force TLS as mandatory to start and server
- Pkg HTTP Server : add function to listen server with multiple handler (map[key string]http.handler)
- Pkg HTTP Server : add option to define an handler key to associate one server with one handler
This commit is contained in:
Nicolas JUHEL
2021-03-04 11:14:31 +01:00
parent 838b1c0c98
commit e457f641d2
5 changed files with 231 additions and 21 deletions

View File

@@ -46,17 +46,27 @@ var tlsConfigSrv = libtls.Config{
}
var cfgSrv01 = libsrv.ServerConfig{
Name: "test-01",
Listen: "0.0.0.0:61001",
Expose: "0.0.0.0:61000",
TLS: tlsConfigSrv,
Name: "test-01",
Listen: "0.0.0.0:61001",
Expose: "0.0.0.0:61000",
TLSMandatory: false,
TLS: tlsConfigSrv,
}
var cfgSrv02 = libsrv.ServerConfig{
Name: "test-02",
Listen: "0.0.0.0:61002",
Expose: "0.0.0.0:61000",
TLS: tlsConfigSrv,
Name: "test-02",
Listen: "0.0.0.0:61002",
Expose: "0.0.0.0:61000",
TLSMandatory: false,
TLS: tlsConfigSrv,
}
var cfgSrv03 = libsrv.ServerConfig{
Name: "test-03",
Listen: "0.0.0.0:61003",
Expose: "0.0.0.0:61000",
TLSMandatory: true,
TLS: tlsConfigSrv,
}
var (
@@ -77,7 +87,7 @@ func init() {
ctx, cnl = context.WithCancel(context.Background())
cfgPool = libsrv.PoolServerConfig{cfgSrv01, cfgSrv02}
cfgPool = libsrv.PoolServerConfig{cfgSrv01, cfgSrv02, cfgSrv03}
cfgPool.MapUpdate(func(cfg libsrv.ServerConfig) libsrv.ServerConfig {
cfg.SetParentContext(func() context.Context {
return ctx
@@ -112,6 +122,24 @@ func main() {
go pool.WaitNotify(ctx, cnl)
go func() {
for {
time.Sleep(5 * time.Second)
if ctx.Err() != nil {
return
}
pool.MapRun(func(srv libsrv.Server) {
n, v, _ := srv.StatusInfo()
if e := srv.StatusHealth(); e != nil {
fmt.Printf("%s - %s : %v\n", n, v, e)
} else {
fmt.Printf("%s - %s : OK\n", n, v)
}
})
}
}()
var i = 0
for {