internal/component => internal/dis/component
This commit is contained in:
parent
9443217441
commit
b5b1ce2340
123 changed files with 76 additions and 76 deletions
30
internal/dis/component/control/server.go
Normal file
30
internal/dis/component/control/server.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Server returns an http.Mux that implements the main server instance.
|
||||
// The server may spawn background tasks, but these should be terminated once context closes.
|
||||
//
|
||||
// Logging messages are directed to io.
|
||||
func (control *Control) Server(context context.Context, io stream.IOStream) (*http.ServeMux, error) {
|
||||
// create a new mux
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// add all the servable routes!
|
||||
for _, s := range control.Servables {
|
||||
for _, route := range s.Routes() {
|
||||
io.Printf("mounting %s\n", route)
|
||||
handler, err := s.Handler(route, context, io)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mux.Handle(route, handler)
|
||||
}
|
||||
}
|
||||
return mux, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue