Skip to content

Commit 705e58e

Browse files
committed
rename package, update README.md
1 parent 8c63cd5 commit 705e58e

File tree

10 files changed

+27
-19
lines changed

10 files changed

+27
-19
lines changed

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131

3232
1. 解析请求,转换 json 数据到 ``
3333

34-
# 开发测试
34+
# 开发指南
35+
0. go version > 1.6
36+
1. 准备数据库
3537
```shell
36-
╰─$ docker run -d -p3306:3306 --name mysql -e MARIADB_ROOT_PASSWORD=123456 mariadb
37-
```
38+
docker run -d -p3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=1234qwer mysql:8
39+
```
40+
2. 创建数据库
41+
3. 导入 [SQL](https://gitee.com/tomyang1898/APIJSON-Demo/blob/master/MySQL/sys.sql)
42+
4. 根据数据库参数修改 main.go 的 db.Init 参数
43+
5. 运行 `go run main.go`

db/db.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ package db
33
import (
44
"database/sql"
55
_ "github.com/go-sql-driver/mysql"
6+
"github.com/j2go/apijson/logger"
67
"github.com/jmoiron/sqlx"
7-
"github.com/keepfoo/apijson/logger"
88
"log"
99
"strings"
1010
)
1111

1212
var db *sqlx.DB
1313

14-
const database = "sys"
15-
const dataSourceName = "root:123456@tcp(localhost:3306)/" + database
16-
const showTableSQL = "select TABLE_NAME from information_schema.tables where table_schema='" + database + "' and table_type='base table'"
1714
const accessAliasSQL = "select name,alias from Access where alias is not null"
1815

1916
type TableMeta struct {
@@ -37,7 +34,10 @@ type Access struct {
3734

3835
var AllTable = make(map[string]TableMeta)
3936

40-
func init() {
37+
func Init(database string, dataSource string) {
38+
dataSourceName := dataSource + "/" + database
39+
showTableSQL := "select TABLE_NAME from information_schema.tables where table_schema='" + database + "' and table_type='BASE TABLE'"
40+
4141
var err error
4242
db, err = sqlx.Open("mysql", dataSourceName)
4343
if err != nil {

db/sqlparser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package db
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/keepfoo/apijson/logger"
6+
"github.com/j2go/apijson/logger"
77
"strconv"
88
"strings"
99
)

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/keepfoo/apijson
1+
module github.com/j2go/apijson
22

33
go 1.16
44

handler/delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handler
22

33
import (
4-
"github.com/keepfoo/apijson/logger"
4+
"github.com/j2go/apijson/logger"
55
"net/http"
66
)
77

handler/get.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package handler
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/keepfoo/apijson/db"
7-
"github.com/keepfoo/apijson/logger"
6+
"github.com/j2go/apijson/db"
7+
"github.com/j2go/apijson/logger"
88
"io/ioutil"
99
"net/http"
1010
"strings"
@@ -36,7 +36,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
3636
}
3737

3838
func cors(w http.ResponseWriter) {
39-
w.Header().Add("Access-Control-Allow-Origin", "http://apijson.cn")
39+
w.Header().Add("Access-Control-Allow-Origin", "http://apijson.cn/")
4040
w.Header().Add("Access-Control-Allow-Credentials", "true")
4141
w.Header().Add("Access-Control-Allow-Headers", "content-type")
4242
w.Header().Add("Access-Control-Request-Method", "POST")

handler/head.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handler
22

33
import (
4-
"github.com/keepfoo/apijson/logger"
4+
"github.com/j2go/apijson/logger"
55
"net/http"
66
)
77

handler/post.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handler
22

33
import (
4-
"github.com/keepfoo/apijson/logger"
4+
"github.com/j2go/apijson/logger"
55
"net/http"
66
)
77

handler/put.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handler
22

33
import (
4-
"github.com/keepfoo/apijson/logger"
4+
"github.com/j2go/apijson/logger"
55
"net/http"
66
)
77

main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package main
22

33
import (
4-
"github.com/keepfoo/apijson/handler"
5-
"github.com/keepfoo/apijson/logger"
4+
"github.com/j2go/apijson/db"
5+
"github.com/j2go/apijson/handler"
6+
"github.com/j2go/apijson/logger"
67
"log"
78
"net/http"
89
)
910

1011
func main() {
12+
db.Init("apijson", "root:1234qwer@tcp(localhost:3306)")
1113
http.HandleFunc("/head", handler.HeadHandler)
1214
http.HandleFunc("/get", handler.GetHandler)
1315
http.HandleFunc("/post", handler.PostHandler)

0 commit comments

Comments
 (0)