From ff5a7ecdb8aa0ccfe4bd4f71648e7254e470c930 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 12 Feb 2026 00:17:29 +0700 Subject: all: change Serve parameters to struct `ServeOptions` In case we needs to add another parameter, which will do later, the argument will be too long. Using parameters is acceptable only for 2 to 3 arguments. --- http_server.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'http_server.go') diff --git a/http_server.go b/http_server.go index e0935c5..cc88798 100644 --- a/http_server.go +++ b/http_server.go @@ -1,5 +1,5 @@ -// SPDX-FileCopyrightText: 2021 M. Shulhan // SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: 2021 M. Shulhan package awwan @@ -11,7 +11,6 @@ import ( "fmt" "io/fs" "log" - "net" "net/http" "os" "path" @@ -41,9 +40,6 @@ const ( paramNameID = `id` ) -// DefListenAddress default HTTP server address to serve WUI. -const DefListenAddress = `127.0.0.1:17600` - // httpServer awwan HTTP server for HTTP API and web user interface feature. type httpServer struct { *libhttp.Server @@ -63,10 +59,8 @@ type httpServer struct { // newHTTPServer create and initialize HTTP server to serve awwan HTTP API // and web user interface. -func newHTTPServer(aww *Awwan, listener net.Listener, address string) (httpd *httpServer, err error) { - var ( - logp = `newHTTPServer` - ) +func newHTTPServer(aww *Awwan, serveOpts ServeOptions) (httpd *httpServer, err error) { + var logp = `newHTTPServer` httpd = &httpServer{ idExecRes: make(map[string]*ExecResponse), @@ -92,13 +86,9 @@ func newHTTPServer(aww *Awwan, listener net.Listener, address string) (httpd *ht return nil, fmt.Errorf(`%s: %w`, logp, err) } - var serverOpts = libhttp.ServerOptions{ - Listener: listener, - Memfs: internal.MemfsWui, - Address: address, - } + serveOpts.Memfs = internal.MemfsWui - httpd.Server, err = libhttp.NewServer(serverOpts) + httpd.Server, err = libhttp.NewServer(serveOpts.ServerOptions) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } -- cgit v1.3