Browse Source

Merge branch 'master' of 208.97.141.22:Matheus/go-bootstrap

William Wiechorek 6 years ago
parent
commit
8a733806de
5 changed files with 33 additions and 2 deletions
  1. BIN
      build
  2. 1 1
      config.go
  3. 3 0
      config/config.go
  4. 27 0
      core/database/database.go
  5. 2 1
      main.go

BIN
build


+ 1 - 1
config.go

1
 package main
1
 package main
2
 
2
 
3
 //ServerPort para escuta do servidor
3
 //ServerPort para escuta do servidor
4
-const ServerPort = 8080
4
+const SERVER_PORT = 8080

+ 3 - 0
config/config.go

1
+package config
2
+
3
+const SERVER_PORT = 8080

+ 27 - 0
core/database/database.go

1
+package models
2
+
3
+import (
4
+	"database/sql"
5
+	"log"
6
+
7
+	_ "github.com/go-sql-driver/mysql"
8
+)
9
+
10
+var db *sql.DB
11
+
12
+func Init(dataSourceName string) error {
13
+
14
+	var err error
15
+
16
+	db, err = sql.Open("mysql", dataSourceName)
17
+
18
+	if err != nil {
19
+		log.Panic(err)
20
+	}
21
+
22
+	if err = db.Ping(); err != nil {
23
+		log.Panic(err)
24
+	}
25
+
26
+	return err
27
+}

+ 2 - 1
main.go

11
 )
11
 )
12
 
12
 
13
 func main() {
13
 func main() {
14
+
14
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
15
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
15
 
16
 
16
 		router.Add(`\/(.*)`, func(w http.ResponseWriter, r *http.Request, vars []string) {
17
 		router.Add(`\/(.*)`, func(w http.ResponseWriter, r *http.Request, vars []string) {
21
 		router.Match(w, r)
22
 		router.Match(w, r)
22
 	})
23
 	})
23
 
24
 
24
-	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(ServerPort), nil))
25
+	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(SERVER_PORT), nil))
25
 }
26
 }