Initial
This commit is contained in:
29
internal/app/apiserver/apiserver.go
Normal file
29
internal/app/apiserver/apiserver.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type contextKey struct {
|
||||
key string
|
||||
}
|
||||
|
||||
var connContextKey = &contextKey{"http-conn"}
|
||||
|
||||
func saveConnInContext(ctx context.Context, c net.Conn) context.Context {
|
||||
return context.WithValue(ctx, connContextKey, c)
|
||||
}
|
||||
|
||||
// Start the server
|
||||
func Start() error {
|
||||
srv := newServer()
|
||||
server := http.Server{
|
||||
Addr: ":8080",
|
||||
ConnContext: saveConnInContext,
|
||||
Handler: srv,
|
||||
}
|
||||
|
||||
return server.ListenAndServe()
|
||||
}
|
||||
Reference in New Issue
Block a user