48 lines
870 B
Go
48 lines
870 B
Go
package main
|
|
|
|
import (
|
|
"code.mrmelon54.xyz/sean/melon-tools/module/gitea"
|
|
"code.mrmelon54.xyz/sean/melon-tools/utils"
|
|
"fmt"
|
|
"github.com/gorilla/mux"
|
|
"github.com/joho/godotenv"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
var modules = map[string]utils.IModule{
|
|
"/gitea": gitea.New(),
|
|
}
|
|
|
|
func main() {
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
|
|
rw.WriteHeader(http.StatusOK)
|
|
_, _ = rw.Write([]byte("Melon Tools\n"))
|
|
})
|
|
for k, v := range modules {
|
|
v.SetupModule(router.Path(k).Subrouter())
|
|
}
|
|
|
|
s := &http.Server{
|
|
Addr: os.Getenv("LISTEN"),
|
|
Handler: router,
|
|
}
|
|
err = s.ListenAndServe()
|
|
if err != nil {
|
|
if err == http.ErrServerClosed {
|
|
log.Println("Server closed successfully")
|
|
} else {
|
|
log.Fatalln(err)
|
|
}
|
|
return
|
|
}
|
|
}
|