Add basic web serving and html templating
This commit is contained in:
parent
18113ea4ee
commit
25039a8f54
8 changed files with 190 additions and 2 deletions
48
main.go
48
main.go
|
|
@ -1,7 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/alexedwards/scs/v2"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
|
||||
var sessionManager *scs.SessionManager
|
||||
|
||||
var BaseURL, ClientID, ClientSecret string
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello World!")
|
||||
ClientID = os.Getenv("ARCGIS_CLIENT_ID")
|
||||
if ClientID == "" {
|
||||
log.Println("You must specify a non-empty CLIENT_ID")
|
||||
os.Exit(1)
|
||||
}
|
||||
ClientSecret = os.Getenv("ARCGIS_CLIENT_SECRET")
|
||||
if ClientSecret == "" {
|
||||
log.Println("You must specify a non-empty CLIENT_SECRET")
|
||||
os.Exit(1)
|
||||
}
|
||||
BaseURL = os.Getenv("BASE_URL")
|
||||
if BaseURL == "" {
|
||||
log.Println("You must specify a non-empty BASE_URL")
|
||||
os.Exit(1)
|
||||
}
|
||||
bind := os.Getenv("BIND")
|
||||
if bind == "" {
|
||||
bind = ":9001"
|
||||
}
|
||||
|
||||
log.Println("Starting...")
|
||||
sessionManager = scs.New()
|
||||
sessionManager.Lifetime = 24 * time.Hour
|
||||
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Logger)
|
||||
r.Use(sessionManager.LoadAndSave)
|
||||
|
||||
r.Get("/", getRoot)
|
||||
r.Get("/favicon.ico", getFavicon)
|
||||
log.Printf("Serving on %s", bind)
|
||||
log.Fatal(http.ListenAndServe(bind, r))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue