-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (60 loc) · 1.76 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
76
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
kafkaservice "github.com/mariaDB/module/kafka-service"
utility "github.com/mariaDB/module/utilities"
"github.com/mariaDB/module/student"
"github.com/mariaDB/module/config"
"github.com/mariaDB/module/database/gormdb"
)
var (
err error
)
func main() {
utility.Logger = log.New(os.Stdout, "", log.Lmicroseconds|log.Lshortfile)
conf := config.ReadEnv()
if conf == nil {
log.Println("Failed to get env variables from .yml file")
return
}
utility.GormDatabase, err = gormdb.NewGormConfig(conf)
if err != nil {
utility.Logger.Println("problem in establishing connection: "+err.Error(), err)
return
}
fmt.Println("After gorm in gorm????????????????????????")
// Create table in db ie mariadb_test
utility.GormDatabase.AutoMigrate(&student.Student{})
// create producer
utility.Producer, err = kafkaservice.InitProducer()
if err != nil {
utility.Logger.Println("Error producer: ", err.Error())
return
}
router := http.NewServeMux()
// router implementation
router.HandleFunc("/", indexHandler)
router.HandleFunc("/api/v1/register", student.Register)
router.HandleFunc("/api/v1/login", student.Login)
// Configuring server ...
server := &http.Server{
Addr: ":" + fmt.Sprint(conf.Server.Port),
Handler: router,
}
flag.String("Listening on port", fmt.Sprint(conf.Server.Port), "port to listen on")
flag.VisitAll(func(flag *flag.Flag) {
log.Println(flag.Name, "->", flag.Value)
})
// Calls serve to handle incoming requst ...
if err := server.ListenAndServe(); err != nil {
utility.Logger.Println("error in spinning up the server: " + err.Error())
return
}
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, welcome to mariadb web app"))
}