60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"JISQueueing/common"
|
|
"JISQueueing/db"
|
|
"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("database", "/etc/queuing/database.sqlite")
|
|
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")
|
|
|
|
var config common.Configuration
|
|
err := viper.Unmarshal(&config)
|
|
if err != nil {
|
|
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
|
}
|
|
}
|
|
|
|
db.Init_DB(config)
|
|
hostLocation := ":" + strconv.Itoa(config.Server.Port)
|
|
mux := server.NewServerMux(config)
|
|
cors := handlers.CORS(
|
|
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}),
|
|
handlers.AllowedMethods([]string{"POST", "OPTIONS"}),
|
|
handlers.AllowedOrigins([]string{"*"}),
|
|
)(mux)
|
|
|
|
if config.Server.SSL {
|
|
crt := config.Server.CertFile
|
|
key := config.Server.KeyFile
|
|
log.Fatal(http.ListenAndServeTLS(hostLocation, crt, key, cors))
|
|
} else {
|
|
log.Fatal(http.ListenAndServe(hostLocation, cors))
|
|
}
|
|
} |