-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
41 lines (37 loc) · 952 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"errors"
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"go.okkur.org/reposeed-server/generator"
"go.okkur.org/reposeed/cmd/config"
)
// SupportedConfigVersion Supported reposeed config version
const SupportedConfigVersion = "v1"
func main() {
err := godotenv.Load()
if err != nil {
log.Println("Couldn't find .env file. Reading environment variables from system")
}
app := gin.Default()
config := &config.Config{}
app.POST("/generate", func(ctx *gin.Context) {
err = ctx.BindJSON(config)
if err != nil {
ctx.AbortWithError(422, errors.New("couldn't parse the given config"))
}
if config.Project.Version == SupportedConfigVersion {
filename, err := generator.CreateFiles(*config)
if err != nil {
ctx.AbortWithError(400, err)
} else {
ctx.File(filename)
}
} else {
ctx.JSON(422, "ConfigVersion: Invalid config version")
}
})
app.Run(os.Getenv("PORT"))
}