diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-07-06 18:06:13 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-07-06 18:06:17 +0530 |
commit | 22ae2f9b78dfdd2f59340d272ef598deb56cc245 (patch) | |
tree | cc7a305cb69cd915e090c63176a08b9dc247a4d2 /api | |
parent | aa57cfdf36407148af613e5633e264a22c4459de (diff) |
go: Init() -> New(), CleanUp() -> Close()
Diffstat (limited to 'api')
-rw-r--r-- | api/main.go | 19 |
1 files changed, 10 insertions, 9 deletions
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() } |