internal/publisher/app.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | package publisher import ( "net/http" "gitlab.com/tozd/go/errors" "go.hacdias.com/indielib/indieauth" "go.alanpearce.eu/homestead/internal/config" ihttp "go.alanpearce.eu/homestead/internal/http" "go.alanpearce.eu/homestead/internal/server" "go.alanpearce.eu/homestead/templates" "go.alanpearce.eu/x/log" ) type Options struct { Development bool `conf:"-"` BaseURL config.URL VCSRemoteURL config.URL `conf:"default:https://git.alanpearce.eu/website"` } type App struct { log *log.Logger indieauthServer *indieauth.Server siteSettings templates.SiteSettings *server.App } func New(opts *Options, log *log.Logger) (*App, errors.E) { var err error app := &App{ log: log, indieauthServer: indieauth.NewServer(true, &http.Client{}), siteSettings: templates.SiteSettings{ Title: "Barkeep", Language: "en-GB", Menu: []config.MenuItem{}, InjectLiveReload: opts.Development, }, App: &server.App{ Domain: opts.BaseURL.Hostname(), Shutdown: func() {}, }, } err = indieauth.IsValidProfileURL(opts.BaseURL.String()) if err != nil { return nil, errors.WithMessage(err, "invalid base URL") } mux := ihttp.NewServeMux() mux.HandleFunc("/", app.Index) mux.HandleFunc("/style.css", app.Style) app.Handler = mux return app, nil } |