gogmagog/main.go
Deepak 3a5961f003
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
adds basic db stuff
2020-12-26 12:44:05 -06:00

56 lines
1.1 KiB
Go

package main
import (
"gitea.deepak.science/deepak/gogmagog/config"
"gitea.deepak.science/deepak/gogmagog/db"
"gitea.deepak.science/deepak/gogmagog/models"
"log"
"net/http"
)
func main() {
// Config
config.Init()
port := config.Port.GetString()
env := config.Environment.GetString()
log.Print("Running server on " + port)
log.Print("App environment is " + env)
// DB
store := db.GetStore()
if store != nil {
log.Print("Got DB connection")
}
m := models.New(store)
if m != nil {
log.Print("created model")
}
http.Handle("/static/", http.FileServer(http.Dir("public")))
http.HandleFunc("/actions/", HandleAction)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
func ShowCompleteActions(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(r.URL.Path))
}
func HandleAction(w http.ResponseWriter, r *http.Request) {
var message string
id := r.URL.Path[len("/actions/"):]
if r.Method == "GET" {
message = "Get the action " + id
} else {
message = r.Method + " the action " + id
}
w.Write([]byte(message))
}
func Hello() string {
return "Hello, world!\n"
}