mirror of
https://github.com/elyby/chrly.git
synced 2026-10-20 20:58:12 +05:30
Split Dispatcher interface and use it across application
This commit is contained in:
5 files changed
+22
-27
No files matched your search
+3
-20
@@ -3,37 +3,20 @@ package http
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mono83/slf"
|
||||
"github.com/mono83/slf/wd"
|
||||
|
||||
"github.com/elyby/chrly/dispatcher"
|
||||
)
|
||||
|
||||
type Emitter interface {
|
||||
Emit(name string, args ...interface{})
|
||||
}
|
||||
|
||||
func Serve(address string, handler http.Handler) error {
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
server := &http.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 5 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
MaxHeaderBytes: 1 << 16,
|
||||
Handler: handler,
|
||||
}
|
||||
|
||||
return server.Serve(listener)
|
||||
dispatcher.Emitter
|
||||
}
|
||||
|
||||
func StartServer(server *http.Server, logger slf.Logger) {
|
||||
|
||||
Reference in new issue
Block a user