DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 8a9527b7a11537389400b79661ef3095cbe2e4f9 deck-builder/sdbapi/main.go -rw-r--r-- 933 bytes
8a9527b7Jonni Liljamo Add window configurations 2 years ago
                                                                                
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
42
43
44
45
46
47
48
49
50
/*
 * This file is part of sdbapi
 * Copyright (C) 2022 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

package main

import (
	"api/db"
	"api/handlers"
	"api/middlewares"
	"log"
	"os"

	"github.com/gin-gonic/gin"
)

func main() {
	dbConnectionString := os.Getenv("GORM_DB_STRING")

	db.Connect(dbConnectionString)

	db.Migrate()

	log.Print("creating router and launching API")
	router := createRouter()
	router.Run(":3000")
}

func createRouter() *gin.Engine {
	router := gin.Default()
	api := router.Group("/api")
	{
		api.GET("/info", handlers.Info)
		user := api.Group("/user")
		{
			user.POST("/register", handlers.CreateUser)
			user.POST("/token", handlers.GenerateToken)
			user.GET("/info/:username", handlers.UserInfo)
			userp := user.Group("/_").Use(middlewares.Auth())
			{
				userp.GET("/info/:id", handlers.UserInfoP)
			}
		}
	}
	return router
}