-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·75 lines (59 loc) · 1.64 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"github.com/BurntSushi/toml"
"github.com/gin-gonic/gin"
//"go-mini-arch/middleware/authentication"
"io"
"log"
_ "net/http"
"./driver/databases"
"./usecases/transaction"
//"orbits-transaction-api/usecases/transaction/customer"
//"orbits-transaction-api/usecases/transaction/inventory"
//"orbits-transaction-api/usecases/transaction/subscription"
"os"
)
type Config struct {
PORT string
}
func main() {
/* Create connection engine */
database.ConnectMgo()
defer database.MgoSession.Close()
/* Getting app configuration */
var config Config
if _, err := toml.DecodeFile("config.toml", &config); err != nil {
log.Println(err)
}
/* Welcome to gin framework ! */
// Disable Console Color, you don't need console color when writing the logs to file.
gin.DisableConsoleColor()
// Logging to a file.
f, _ := os.Create("gin.log")
gin.DefaultWriter = io.MultiWriter(f)
/* Create gin route */
//r := gin.Default()
r := gin.Default()
/* Inject mongo session to Gin Context*/
r.Use(mapMongo)
/* Bind route to middleware (in this case authentication)*/
// r.Use(authentication.Authentication)
Transaction := r.Group("/transaction")
{
List := Transaction.Group("/list")
{
List.GET("/getbyall", transaction.GetByTransactionList)
List.POST("/getbysearch", transaction.GetByTransactionListSearch)
}
}
/* Register some route (ping) and bind it to certain usecase(controller) */
/* Listen and serve to a port */
r.Run(config.PORT)
}
/* put mongo db session to gin context */
func mapMongo(c *gin.Context) {
session := database.MgoSession.Clone()
defer session.Close()
c.Set("mongoSession", session)
c.Next()
}