Skip to content

Commit

Permalink
Merge pull request #565 from wayyoungboy/master
Browse files Browse the repository at this point in the history
support OceanBase
  • Loading branch information
cg33 authored Apr 6, 2023
2 parents 54edfd1 + ce8b398 commit e21f811
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ $ adm init web
- [mssql](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.mssql)
- [postgresql](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.pgsql)
- [sqlite](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.db)
- [OceanBase](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.sql)


### Step 2: create main.go

Expand Down
4 changes: 2 additions & 2 deletions adm/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package main

import (
"fmt"
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/oceanbase"
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/postgres"
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/sqlite"

"fmt"
"os"
"runtime"
"runtime/debug"
Expand Down
10 changes: 10 additions & 0 deletions adm/project_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ func buildProjectWeb(port string) {
_, _ = w.Write([]byte(`{"code": 400, "msg": "` + local(lang)("web.wrong parameter") + `: ` + field + `"}`))
return
}
} else if r.PostFormValue("db_type") == "oceanbase" {
if field, ok := checkEmpty([]string{"db_port", "db_host", "db_user", "db_name"}, r); !ok {
w.WriteHeader(http.StatusOK)
w.Header().Add("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"code": 400, "msg": "` + local(lang)("web.wrong parameter") + `: ` + field + `"}`))
return
}

} else {
if field, ok := checkEmpty([]string{"db_port", "db_host", "db_user", "db_passwd", "db_name"}, r); !ok {
w.WriteHeader(http.StatusOK)
Expand Down Expand Up @@ -242,6 +250,8 @@ func buildProjectWeb(port string) {
if err := http.Serve(l, nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
fmt.Println("GoAdmin web install program start.")

}(startChan)

<-startChan
Expand Down
38 changes: 37 additions & 1 deletion adm/project_web.tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ var projectWebTmpl = `
<div class="item" data-value="postgresql">PostgreSQL</div>
<div class="item" data-value="mssql">MSSQL</div>
<div class="item" data-value="sqlite">SQLite3</div>
<div class="item" data-value="oceanbase">OceanBase</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -233,7 +235,29 @@ var projectWebTmpl = `
<span class="help">{{local "web.the file path of sqlite3 database"}}<br>{{local "web.please use absolute path when you start as service"}}</span>
</div>
</div>
<div id="oceanbase_settings" class="hide">
<div class="inline required field ">
<label for="db_host">{{local "web.database host"}}</label>
<input id="db_host" name="db_host" value="127.0.0.1">
</div>
<div class="inline required field ">
<label for="db_port">{{local "web.database port"}}</label>
<input id="db_port" name="db_port" value="2883">
</div>
<div class="inline required field ">
<label for="db_user">{{local "web.database user"}}</label>
<input id="db_user" name="db_user" value="root@sys">
</div>
<div class="inline required field ">
<label for="db_passwd">{{local "web.database password"}}</label>
<input id="db_passwd" name="db_passwd" type="password" value="">
</div>
<div class="inline required field ">
<label for="db_name">{{local "web.database name"}}</label>
<input id="db_name" name="db_name" value="goadmin">
<span class="help">{{local "web.where the framework sql data install to"}}</span>
</div>
</div>
<h4 class="ui dividing header">{{local "web.installation settings"}}</h4>
<div class="inline required field ">
Expand Down Expand Up @@ -370,6 +394,9 @@ var projectWebTmpl = `
<li>
<a href="https://gitee.com/go-admin/go-admin/raw/master/data/admin.db" target="_blank">SQLite3</a>
</li>
<li>
<a href="https://gitee.com/go-admin/go-admin/raw/master/data/admin.sql" target="_blank">OceanBase</a>
</li>
</ul>
<p>
2. 依次执行以下命令:
Expand Down Expand Up @@ -455,6 +482,10 @@ var projectWebTmpl = `
<a href="https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.db"
target="_blank">SQLite3</a>
</li>
<li>
<a href="https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.sql"
target="_blank">OceanBase</a>
</li>
</ul>
<p>
2. Execute the following command in turn
Expand Down Expand Up @@ -587,6 +618,11 @@ var projectWebTmpl = `
"addr": "127.0.0.1",
"port": "1433",
"user": "sa"
},
"oceanbase": {
"addr": "127.0.0.1",
"port": "2881",
"user": "root@sys"
}
};
Expand Down
5 changes: 5 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ func (eng *Engine) SqliteConnection() db.Connection {
return db.GetConnectionFromService(eng.Services.Get(db.DriverSqlite))
}

// OceanBaseConnection return the OceanBase db connection of given driver.
func (eng *Engine) OceanBaseConnection() db.Connection {
return db.GetConnectionFromService(eng.Services.Get(db.DriverOceanBase))
}

type ConnectionSetter func(db.Connection)

// ResolveConnection resolve the specified driver connection.
Expand Down
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ go 1.13

require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
github.com/GoAdminGroup/html v0.0.1
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e
github.com/go-sql-driver/mysql v1.5.0
github.com/google/uuid v1.3.0 // indirect
github.com/jawher/mow.cli v1.2.0 // indirect
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lib/pq v1.3.0
github.com/magiconair/properties v1.8.1
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/schollz/progressbar v1.0.0 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/stretchr/testify v1.6.1
github.com/tdewolff/minify/v2 v2.12.4 // indirect
go.uber.org/zap v1.14.1
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c // indirect
golang.org/x/text v0.3.2
golang.org/x/text v0.3.3
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/ini.v1 v1.51.0
gopkg.in/yaml.v2 v2.2.8
Expand Down
Loading

0 comments on commit e21f811

Please sign in to comment.