barkeep: initial commit
1 file changed, 58 insertions(+), 0 deletions(-)
changed files
A internal/publisher/app.go
@@ -0,0 +1,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 +}