You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
574 B
34 lines
574 B
package app |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
"net/http" |
|
|
|
"lol.mleku.dev/chk" |
|
"lol.mleku.dev/log" |
|
"next.orly.dev/app/config" |
|
) |
|
|
|
func Run(ctx context.Context, cfg *config.C) (quit chan struct{}) { |
|
// shutdown handler |
|
go func() { |
|
select { |
|
case <-ctx.Done(): |
|
log.I.F("shutting down") |
|
close(quit) |
|
} |
|
}() |
|
// start listener |
|
l := &Server{ |
|
Ctx: ctx, |
|
Config: cfg, |
|
} |
|
addr := fmt.Sprintf("%s:%d", cfg.Listen, cfg.Port) |
|
log.I.F("starting listener on http://%s", addr) |
|
go func() { |
|
chk.E(http.ListenAndServe(addr, l)) |
|
}() |
|
quit = make(chan struct{}) |
|
return |
|
}
|
|
|