"git.christiangoeschel.com/repoman/cmd/healthchecker"
"git.christiangoeschel.com/repoman/cmd/configparse"
"os"
+ "fmt"
)
+type APIServerInfo struct {
+
+ Version string `json:"Version"`
+}
+
+func getAPIServerInfo(c *gin.Context) {
+
+ apiInfo := APIServerInfo {
+ Version: "0.1.0924 beta",
+ }
+
+ c.IndentedJSON(http.StatusOK, apiInfo)
+
+}
func reportHealthStatus(c *gin.Context) {
}
+func setupNetSocket(c *configparse.Config) (netSocket string, err error){
+
+ netSocket = fmt.Sprintf("%s:%d", c.Network.Host, c.Network.ListenPort)
+
+ return netSocket, nil
+}
+
+func startServer(c *configparse.Config, netSocket string, r *gin.Engine) (err error){
+
+ if c.Network.EnableSSL == true {
+ err = r.RunTLS((netSocket), c.SSL.CertFile, c.SSL.KeyFile)
+ if err != nil {
+ return err
+ }
+ } else {
+ err = r.Run(netSocket)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
func main() {
- var TLSCertificates *configparse.TLSCertificates
+ var config = configparse.Config{}
- TLSCertificates, err := configparse.GetTLSCertificates()
+ err := configparse.GetConfig( &config )
if err != nil {
+ fmt.Printf("Failed to parse config file\nDetails: %s", err)
os.Exit(1)
}
router := gin.Default()
+ router.GET("/info", getAPIServerInfo)
router.GET("/status", reportHealthStatus)
- router.RunTLS(("0.0.0.0:8443"), TLSCertificates.TLS.CertFile, TLSCertificates.TLS.KeyFile)
+
+ netSocket, err := setupNetSocket(&config)
+ if err != nil {
+ fmt.Printf("Failed to setup network socket\nDetails: %s\n", err)
+ os.Exit(1)
+ }
+ err = startServer(&config, netSocket, router)
+ if err != nil {
+ fmt.Printf("Failed to start API server\nDetails: %s\n", err)
+ os.Exit(1)
+ }
}
"github.com/go-ini/ini"
)
-type TLSCertificates struct {
- TLS struct {
- CertFile string `ini:"CertFile"`
- KeyFile string `ini:"KeyFile"`
- } `ini:"TLS"`
+// Stores the SSL certificates' filesystem locations
+type Config struct {
-}
+ SSL struct {
+ CertFile string `ini:"CertFile"`
+ KeyFile string `ini:"KeyFile"`
+ } `ini:"SSL"`
+
+ Network struct {
+ Host string `ini:"Host"`
+ ListenPort int `ini:"ListenPort"`
+ EnableSSL bool `ini:"EnableSSL"`
+ }`ini:"Network"`
-var TLSCerts TLSCertificates
+ Repo struct {
+ DefaultGitDirectory string `ini:"DefaultGitDirectory"`
+ } `ini:"Repo"`
-func GetTLSCertificates() (tlsCerts *TLSCertificates ,err error) {
+}
+
+// Extracts the configured filesystem locations for the SSL certificates
+func GetConfig( c *Config ) (err error) {
+
iniData, err := ini.Load("/etc/repoman/config.ini")
if err != nil {
- return nil, err
+ return err
}
- err = iniData.MapTo(&TLSCerts)
+ err = iniData.MapTo(&c)
if err != nil {
- return nil, err
+ return err
}
- return &TLSCerts, nil
+ return nil
}
+