This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
JISQueueing/main.go

56 lines
1.5 KiB
Go

package main
import (
"JISQueueing/server"
"fmt"
"github.com/spf13/viper"
"log"
"net/http"
"strconv"
"github.com/gorilla/handlers"
)
func main() {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("/etc/queuing")
viper.SetDefault("debug", false)
viper.SetDefault("ip", "10.1.3.100")
viper.SetDefault("server.ssl", true)
viper.SetDefault("server.certFile", "/etc/queuing/server.crt")
viper.SetDefault("server.keyFile", "/etc/queuing/server.key")
viper.SetDefault("server.port", 433)
viper.SetDefault("redis.addr", "10.1.3.100:6379")
viper.SetDefault("redis.channel", "qq")
viper.SetDefault("mail.host", "mail1.jisedu.or.id")
viper.SetDefault("mail.port", 25)
viper.SetDefault("mail.username", "IT.Q@jisedu.or.id")
viper.SetDefault("mail.logo", "/etc/queuing/logo.jpg")
err := viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
hostLocation := ":" + strconv.Itoa(viper.GetInt("port"))
mux := server.NewServerMux()
cors := handlers.CORS(
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}),
handlers.AllowedMethods([]string{"POST", "OPTIONS"}),
handlers.AllowedOrigins([]string{"*"}),
)(mux)
if viper.GetBool("server.ssl") {
crt := viper.GetString("server.certFile")
key := viper.GetString("server.keyFile")
log.Fatal(http.ListenAndServeTLS(hostLocation, crt, key, cors))
} else {
log.Fatal(http.ListenAndServe(hostLocation, cors))
}
}