-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
48 lines (38 loc) · 1.29 KB
/
server.go
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
package main
import (
"fmt"
"github.com/gorilla/mux"
_ "github.com/mattn/go-sqlite3"
"log"
"net/http"
"os"
)
var PORT = os.Getenv("PORT")
// Set up logging
var (
InfoLogger *log.Logger
WarnLogger *log.Logger
ErrLogger *log.Logger
)
func init() {
InfoLogger = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
WarnLogger = log.New(os.Stdout, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile)
ErrLogger = log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
}
func main() {
InfoLogger.Println("Starting server...")
InfoLogger.Printf("Server started at port: %s", PORT)
serverAddress := fmt.Sprintf(":%s", PORT)
// Fucking mux router makes trailing slash mandatory. WTF?
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/login", loginHandler).Methods("POST")
router.HandleFunc("/register", registerHandler).Methods("POST")
router.HandleFunc("/add-package", addPackageHandler).Methods("POST")
router.HandleFunc("/ping", pingHandler).Methods("GET")
router.HandleFunc("/config", configHandler).Methods("GET")
router.HandleFunc("/archives/{user}/{name}", getArchiveHandler).Methods("GET")
router.HandleFunc("/get-package/{name}", getPackagesHandler).Methods("GET")
if err := http.ListenAndServe(serverAddress, router); err != nil {
log.Fatal(err)
}
}