summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/cfg/cfg.go (renamed from pkg/srv/config.go)12
-rw-r--r--pkg/cfg/mux.go9
-rw-r--r--pkg/cfg/option.go3
-rw-r--r--pkg/srv/srv.go12
4 files changed, 21 insertions, 15 deletions
diff --git a/pkg/srv/config.go b/pkg/cfg/cfg.go
index c02a9c7a..0d7a6427 100644
--- a/pkg/srv/config.go
+++ b/pkg/cfg/cfg.go
@@ -1,25 +1,17 @@
-package srv
+package cfg
import (
"crypto/tls"
"net/http"
)
-type Option func(*Config)
-
type Config struct {
BindAddress string
Mux http.Handler
TLS *tls.Config
}
-func WithMux(mux http.Handler) Option {
- return func(config *Config) {
- config.Mux = mux
- }
-}
-
-func NewConfig(addr string, options ...Option) *Config {
+func New(addr string, options ...Option) *Config {
if addr == "" {
addr = ":0"
}
diff --git a/pkg/cfg/mux.go b/pkg/cfg/mux.go
new file mode 100644
index 00000000..694ee9e7
--- /dev/null
+++ b/pkg/cfg/mux.go
@@ -0,0 +1,9 @@
+package cfg
+
+import "net/http"
+
+func WithMux(mux http.Handler) Option {
+ return func(config *Config) {
+ config.Mux = mux
+ }
+}
diff --git a/pkg/cfg/option.go b/pkg/cfg/option.go
new file mode 100644
index 00000000..0f3e87d8
--- /dev/null
+++ b/pkg/cfg/option.go
@@ -0,0 +1,3 @@
+package cfg
+
+type Option func(*Config)
diff --git a/pkg/srv/srv.go b/pkg/srv/srv.go
index a2be3635..a6261ef6 100644
--- a/pkg/srv/srv.go
+++ b/pkg/srv/srv.go
@@ -4,13 +4,15 @@ import (
"log"
"net/http"
"time"
+
+ "gitlab.com/mokhax/spike/pkg/cfg"
)
-func New(cfg *Config) *http.Server {
+func New(c *cfg.Config) *http.Server {
return &http.Server{
- Addr: cfg.BindAddress,
- Handler: cfg.Mux,
- TLSConfig: cfg.TLS,
+ Addr: c.BindAddress,
+ Handler: c.Mux,
+ TLSConfig: c.TLS,
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 2 * time.Minute,
@@ -19,6 +21,6 @@ func New(cfg *Config) *http.Server {
}
}
-func Run(c *Config) error {
+func Run(c *cfg.Config) error {
return c.Run(New(c))
}