-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
63 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"go.uber.org/fx" | ||
) | ||
|
||
func Module(addr string) fx.Option { | ||
return fx.Options( | ||
fx.Provide(fx.Annotate(NewRouter, fx.As(new(http.Handler)))), | ||
fx.Invoke(func(lc fx.Lifecycle, handler http.Handler) { | ||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
return StartServer(addr, handler) | ||
}, | ||
}) | ||
}), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
func NewRouter() *mux.Router { | ||
router := mux.NewRouter() | ||
|
||
return router | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package api | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
) | ||
|
||
func StartServer(addr string, handler http.Handler) error { | ||
socket, err := net.Listen("tcp", addr) | ||
if err != nil { | ||
return err | ||
} | ||
go func() { | ||
err := http.Serve(socket, handler) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}() | ||
return nil | ||
} |