website/pkg/webserver.go
Noah dd1e6c2918 Initial commit
* Initial codebase (lot of work!)
* Uses vanilla Go net/http and implements by hand: session cookies
  backed by Redis; log in/out; CSRF protection; email verification flow;
  initial database models (User table)
2022-08-09 22:32:19 -07:00

36 lines
663 B
Go

package gosocial
import (
"fmt"
"net/http"
"git.kirsle.net/apps/gosocial/pkg/log"
"git.kirsle.net/apps/gosocial/pkg/router"
)
// WebServer is the main entry point for the `gosocial web` command.
type WebServer struct {
// Configuration
Host string // host interface, default "0.0.0.0"
Port int // default 8080
}
// Run the server.
func (ws *WebServer) Run() error {
// Defaults
if ws.Host == "" {
ws.Host = "0.0.0.0"
}
if ws.Port == 0 {
ws.Port = 8080
}
s := http.Server{
Addr: fmt.Sprintf("%s:%d", ws.Host, ws.Port),
Handler: router.New(),
}
log.Info("Listening at http://%s:%d", ws.Host, ws.Port)
return s.ListenAndServe()
}