diff --git a/config.go b/config.go index f65e852..c78c4d5 100644 --- a/config.go +++ b/config.go @@ -17,6 +17,12 @@ type AppConfig struct { LeanWork struct { MD5Key string `json:MD5Key` } `json:LeanWork` + DB struct { + Driver string `json:Driver` + User string `json:User` + Pass string `json:Pass` + Schema string `json:Schema` + } `json:DB` } var Config AppConfig diff --git a/config.json b/config.json index 166eeb9..e1d85f2 100644 --- a/config.json +++ b/config.json @@ -7,5 +7,11 @@ }, "LeanWork" :{ "MD5Key" : "492815086935204" - } + }, + "DB" :{ + "Driver": "mysql", + "User" : "sp", + "Pass" : "sp", + "Schema": "goblog" + } } \ No newline at end of file diff --git a/config.test.json b/config.test.json index 166eeb9..25cd387 100644 --- a/config.test.json +++ b/config.test.json @@ -7,5 +7,11 @@ }, "LeanWork" :{ "MD5Key" : "492815086935204" + }, + "DB" :{ + "Driver": "mysql", + "User" : "sp", + "Pass" : "sp", + "Schema": "goblog" } } \ No newline at end of file diff --git a/db.go b/db.go index a5f44d8..9f0e9a8 100644 --- a/db.go +++ b/db.go @@ -5,6 +5,8 @@ import ( "log" "net/http" "text/template" + + _ "github.com/go-sql-driver/mysql" ) type Employee struct { @@ -14,10 +16,10 @@ type Employee struct { } func dbConn() (db *sql.DB) { - dbDriver := "mysql" - dbUser := "sp" - dbPass := "sp" - dbName := "goblog" + dbDriver := Config.DB.Driver + dbUser := Config.DB.User + dbPass := Config.DB.Pass + dbName := Config.DB.Schema db, err := sql.Open(dbDriver, dbUser+":"+dbPass+"@/"+dbName) if err != nil { panic(err.Error()) diff --git a/main.go b/main.go index 0debf35..3937313 100644 --- a/main.go +++ b/main.go @@ -3,21 +3,19 @@ package main import ( "log" "net/http" - - _ "github.com/go-sql-driver/mysql" ) func main() { readConfig() log.Println("Server started on: http://localhost:8080") - http.HandleFunc("/", StartPay) + //http.HandleFunc("/", StartPay) - //http.HandleFunc("/", Index) - // http.HandleFunc("/show", Show) - // http.HandleFunc("/new", New) - // http.HandleFunc("/edit", Edit) - // http.HandleFunc("/insert", Insert) - // http.HandleFunc("/update", Update) - // http.HandleFunc("/delete", Delete) + http.HandleFunc("/", Index) + http.HandleFunc("/show", Show) + http.HandleFunc("/new", New) + http.HandleFunc("/edit", Edit) + http.HandleFunc("/insert", Insert) + http.HandleFunc("/update", Update) + http.HandleFunc("/delete", Delete) http.ListenAndServe(":8080", nil) } diff --git a/purchase.go b/purchase.go index dc16379..633fd96 100644 --- a/purchase.go +++ b/purchase.go @@ -7,7 +7,7 @@ import ( func StartPay(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { - fmt.Fprintf(w, "fuck") + fmt.Fprintf(w, "invalid request") return } r.ParseForm()