gull/server.go
lexik a793e3d22c Update 'server.go'
remote the /all fuctionality
2020-08-11 00:30:00 +02:00

31 lines
673 B
Go

package main
import (
"github.com/aeolyus/gull/handlers"
"github.com/gorilla/mux"
"log"
"net/http"
"os"
"strconv"
)
const (
publicDir string = "./public"
port int = 8081
)
func main() {
a := &handlers.App{}
os.MkdirAll("./data", os.ModePerm)
a.Initialize("sqlite3", "./data/data.db")
defer a.DB.Close()
r := mux.NewRouter()
r.HandleFunc("/", a.CreateShortURL).Methods("POST")
r.HandleFunc("/s/{alias:.*}", a.GetURL).Methods("GET")
r.PathPrefix("/").Handler(http.FileServer(http.Dir(publicDir))).Methods("GET")
http.Handle("/", r)
log.Println("Server is listening on port", port)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), nil))
}