Files
golib/httpserver/model.go
nabbar fa8adbe7c8 Package Socket:
- config Server: change time duration to golib duration to simplify
  marshal string form
- adjust test following update of config server
- fix test in socket package to use BDD framework & gherkin form
- adjust documentation & test

Package HTTPServer:
- Fix bug in PortUse & PortNotUse
- Move function PortUse & PortNotUse as alone function
- Add test & documentation
- Unify test & documentation following other packages
2025-12-23 16:27:47 +01:00

54 lines
2.2 KiB
Go

/*
* MIT License
*
* Copyright (c) 2025 Nicolas JUHEL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
package httpserver
import (
"net/http"
libatm "github.com/nabbar/golib/atomic"
libctx "github.com/nabbar/golib/context"
srvtps "github.com/nabbar/golib/httpserver/types"
liblog "github.com/nabbar/golib/logger"
librun "github.com/nabbar/golib/runner/startStop"
)
// srv is the internal server implementation structure.
// It uses atomic values for thread-safe access to handlers, loggers, and state.
type srv struct {
c libctx.Config[string] // Configuration storage with context
h libatm.Value[srvtps.FuncHandler] // Handler function atomic reference
l libatm.Value[liblog.FuncLog] // Logger function atomic reference
r libatm.Value[librun.StartStop] // Runner for lifecycle management
s libatm.Value[*http.Server] // Standard library HTTP server reference
}
// Merge combines configuration from another server instance into this one.
// This updates the current server's configuration with the provided server's settings.
func (o *srv) Merge(s Server, def liblog.FuncLog) error {
return o.SetConfig(*s.GetConfig(), def)
}