30 lines
476 B
Go
30 lines
476 B
Go
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()
|
|
}
|