Captain Hook - Web hook server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
997 B

package main
import (
"log"
"net/http"
"os"
)
// func init() {
// // Loads values from .env into the system
// if err := godotenv.Load(); err != nil {
// log.Println("No .env file found")
// }
// }
func main() {
var err error
db, err = connectDB()
if err != nil {
log.Fatal(err)
}
defer db.Close()
go pingDB(db)
// Get listen address and port
addr, exists := os.LookupEnv("LISTEN")
checkExists(exists, "Couldn't find listen address")
port, exists := os.LookupEnv("PORT")
checkExists(exists, "Couldn't find port")
// Handle hooks
http.HandleFunc("/hook/", hookHandler)
http.HandleFunc("/", index)
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("html/css"))))
http.Handle("/imgs/", http.StripPrefix("/imgs/", http.FileServer(http.Dir("html/imgs"))))
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("html/js"))))
// Start the server
log.Println("Starting server")
log.Fatal(http.ListenAndServe(addr+":"+port, nil))
}