2023-01-19 15:49:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2023-01-24 17:40:54 +00:00
|
|
|
"netoik.io/netoik-api/pkg/captcha"
|
|
|
|
"netoik.io/netoik-api/pkg/conf"
|
|
|
|
"netoik.io/netoik-api/pkg/contact"
|
2023-01-19 15:49:23 +00:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Parse command line arguments
|
|
|
|
path := flag.String("c", "server.conf", "Config file")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// Parse config file
|
|
|
|
if !conf.ParseFile(*path) {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup captcha
|
|
|
|
captcha.Setup()
|
|
|
|
|
|
|
|
// Declare api routes
|
|
|
|
http.HandleFunc("/api/contact/send", contact.HandleSend)
|
|
|
|
http.HandleFunc("/api/captcha/new", captcha.HandleNew)
|
|
|
|
|
|
|
|
// Start listening
|
|
|
|
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", conf.Conf.BindHost, conf.Conf.BindPort), nil); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "cannot listen at %s:%d: %s\n", conf.Conf.BindHost, conf.Conf.BindPort, err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|