From 22ae2f9b78dfdd2f59340d272ef598deb56cc245 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 6 Jul 2024 18:06:13 +0530 Subject: go: Init() -> New(), CleanUp() -> Close() --- api/main.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'api') diff --git a/api/main.go b/api/main.go index 5ce05c1..69cf981 100644 --- a/api/main.go +++ b/api/main.go @@ -13,20 +13,21 @@ type Api struct { sock net.Listener } -func (a *Api) Init() error { +func Close(a *Api) { + a.sock.Close() +} + +func New() (*Api, error) { var err error + var a Api a.sock, err = net.Listen("unix", sockPath) if err != nil { log.Printf("listening on unix socket: %s", err) - return err + return nil, err } - return nil -} - -func handleConn(conn net.Conn) { - defer conn.Close() + return &a, nil } func (a *Api) Run(u *usage.Usage) { @@ -41,6 +42,6 @@ func (a *Api) Run(u *usage.Usage) { } } -func (a *Api) CleanUp() { - a.sock.Close() +func handleConn(conn net.Conn) { + defer conn.Close() } -- cgit v1.2.3