Rename server options struct and init func
This commit is contained in:
parent
1a4f6ebaf2
commit
496f246a2d
|
@ -0,0 +1,23 @@
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ytdl-web:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
- uses: github.com/docker/setup-qemu-action@v2
|
||||||
|
- uses: github.com/docker/setup-buildx-action@v2
|
||||||
|
- uses: github.com/goreleaser/goreleaser-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
args: release --snapshot --clean
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
@ -46,7 +46,7 @@ thousand websites using the yt-dlp project under the hood.`,
|
||||||
ytdl := ytdl.NewYtdl(cfg, slog.Default(), cache)
|
ytdl := ytdl.NewYtdl(cfg, slog.Default(), cache)
|
||||||
|
|
||||||
s := server.New(
|
s := server.New(
|
||||||
server.DefaultServerOptions().
|
server.DefaultOptions().
|
||||||
WithListenAddr(viper.GetString("http.listen")).
|
WithListenAddr(viper.GetString("http.listen")).
|
||||||
WithListenPort(viper.GetInt("http.port")).
|
WithListenPort(viper.GetInt("http.port")).
|
||||||
WithLogger(logger.With("module", "server")),
|
WithLogger(logger.With("module", "server")),
|
||||||
|
|
|
@ -2,31 +2,31 @@ package server
|
||||||
|
|
||||||
import "golang.org/x/exp/slog"
|
import "golang.org/x/exp/slog"
|
||||||
|
|
||||||
type ServerOptions struct {
|
type Options struct {
|
||||||
ListenAddr string
|
ListenAddr string
|
||||||
ListenPort int
|
ListenPort int
|
||||||
Logger *slog.Logger
|
Logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultServerOptions() *ServerOptions {
|
func DefaultOptions() *Options {
|
||||||
return &ServerOptions{
|
return &Options{
|
||||||
ListenAddr: "127.0.0.1",
|
ListenAddr: "127.0.0.1",
|
||||||
ListenPort: 8080,
|
ListenPort: 8080,
|
||||||
Logger: slog.Default(),
|
Logger: slog.Default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ServerOptions) WithListenAddr(addr string) *ServerOptions {
|
func (o *Options) WithListenAddr(addr string) *Options {
|
||||||
o.ListenAddr = addr
|
o.ListenAddr = addr
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ServerOptions) WithListenPort(port int) *ServerOptions {
|
func (o *Options) WithListenPort(port int) *Options {
|
||||||
o.ListenPort = port
|
o.ListenPort = port
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ServerOptions) WithLogger(logger *slog.Logger) *ServerOptions {
|
func (o *Options) WithLogger(logger *slog.Logger) *Options {
|
||||||
o.Logger = logger
|
o.Logger = logger
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,17 +17,17 @@ type Server interface {
|
||||||
|
|
||||||
type DefaultServer struct {
|
type DefaultServer struct {
|
||||||
r chi.Router
|
r chi.Router
|
||||||
opts *ServerOptions
|
opts *Options
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Server = (*DefaultServer)(nil)
|
var _ Server = (*DefaultServer)(nil)
|
||||||
|
|
||||||
func New(options ...*ServerOptions) *DefaultServer {
|
func New(options ...*Options) *DefaultServer {
|
||||||
var opts *ServerOptions
|
var opts *Options
|
||||||
if len(options) > 0 {
|
if len(options) > 0 {
|
||||||
opts = options[0]
|
opts = options[0]
|
||||||
} else {
|
} else {
|
||||||
opts = DefaultServerOptions()
|
opts = DefaultOptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
Loading…
Reference in New Issue