Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
093826222a | ||
|
|
0d7b487afc | ||
|
|
8de17b6d9c | ||
|
|
49d217a883 | ||
|
|
4827555899 |
@@ -1,7 +1,7 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.5.3"
|
Version = "0.5.3.1"
|
||||||
|
|
||||||
ProductName = "Edge API"
|
ProductName = "Edge API"
|
||||||
ProcessName = "edge-api"
|
ProcessName = "edge-api"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package models
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,47 +28,3 @@ func (this *NSCluster) HasDDoSProtection() bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeHosts 解析主机地址
|
|
||||||
func (this *NSCluster) DecodeHosts() []string {
|
|
||||||
if IsNull(this.Hosts) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var hosts = []string{}
|
|
||||||
err := json.Unmarshal(this.Hosts, &hosts)
|
|
||||||
if err != nil {
|
|
||||||
remotelogs.Error("NSCluster.DecodeHosts", "decode failed: "+err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return hosts
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeSOAConfig 解析SOA设置
|
|
||||||
func (this *NSCluster) DecodeSOAConfig() *dnsconfigs.NSSOAConfig {
|
|
||||||
var config = dnsconfigs.DefaultNSSOAConfig()
|
|
||||||
if IsNull(this.Soa) {
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
err := json.Unmarshal(this.Soa, config)
|
|
||||||
if err != nil {
|
|
||||||
remotelogs.Error("NSCluster.DecodeSOAConfig", "decode failed: "+err.Error())
|
|
||||||
}
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeAnswerConfig 解析应答设置
|
|
||||||
func (this *NSCluster) DecodeAnswerConfig() *dnsconfigs.NSAnswerConfig {
|
|
||||||
var config = dnsconfigs.DefaultNSAnswerConfig()
|
|
||||||
|
|
||||||
if IsNull(this.Answer) {
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
err := json.Unmarshal(this.Answer, config)
|
|
||||||
if err != nil {
|
|
||||||
remotelogs.Error("NSCluster.DecodeAnswerConfig", "decode failed: "+err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|||||||
21
internal/dnsclients/edgeapi/response_base.go
Normal file
21
internal/dnsclients/edgeapi/response_base.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BaseResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *BaseResponse) IsValid() bool {
|
||||||
|
return this.Code == 200
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *BaseResponse) Error() error {
|
||||||
|
return errors.New("code: " + types.String(this.Code) + ", message: " + this.Message)
|
||||||
|
}
|
||||||
11
internal/dnsclients/edgeapi/response_create_ns_record.go
Normal file
11
internal/dnsclients/edgeapi/response_create_ns_record.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type CreateNSRecordResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
|
||||||
|
Data struct {
|
||||||
|
NSRecordId int64 `json:"nsRecordId"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
14
internal/dnsclients/edgeapi/response_find_all_ns_routes.go
Normal file
14
internal/dnsclients/edgeapi/response_find_all_ns_routes.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type FindAllNSRoutesResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
|
||||||
|
Data struct {
|
||||||
|
NSRoutes []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
} `json:"nsRoutes"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type FindDomainWithNameResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
|
||||||
|
Data struct {
|
||||||
|
NSDomain struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type FindNSRecordWithNameAndTypeResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
|
||||||
|
Data struct {
|
||||||
|
NSRecord struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
TTL int32 `json:"ttl"`
|
||||||
|
NSRoutes []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
} `json:"nsRoutes"`
|
||||||
|
} `json:"nsRecord"`
|
||||||
|
}
|
||||||
|
}
|
||||||
12
internal/dnsclients/edgeapi/response_get_api_access_token.go
Normal file
12
internal/dnsclients/edgeapi/response_get_api_access_token.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type GetAPIAccessToken struct {
|
||||||
|
BaseResponse
|
||||||
|
|
||||||
|
Data struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
ExpiresAt int64 `json:"expiresAt"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
8
internal/dnsclients/edgeapi/response_interface.go
Normal file
8
internal/dnsclients/edgeapi/response_interface.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type ResponseInterface interface {
|
||||||
|
IsValid() bool
|
||||||
|
Error() error
|
||||||
|
}
|
||||||
16
internal/dnsclients/edgeapi/response_list_ns_domains.go
Normal file
16
internal/dnsclients/edgeapi/response_list_ns_domains.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type ListNSDomainsResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
|
||||||
|
Data struct {
|
||||||
|
NSDomains []struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
IsOn bool `json:"isOn"`
|
||||||
|
IsDeleted bool `json:"isDeleted"`
|
||||||
|
} `json:"nsDomains"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
21
internal/dnsclients/edgeapi/response_list_ns_records.go
Normal file
21
internal/dnsclients/edgeapi/response_list_ns_records.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type ListNSRecordsResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
|
||||||
|
Data struct {
|
||||||
|
NSRecords []struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
TTL int32 `json:"ttl"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
NSRoutes []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
} `json:"nsRoutes"`
|
||||||
|
} `json:"nsRecords"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
7
internal/dnsclients/edgeapi/response_success.go
Normal file
7
internal/dnsclients/edgeapi/response_success.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type SuccessResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
}
|
||||||
7
internal/dnsclients/edgeapi/response_update_ns_record.go
Normal file
7
internal/dnsclients/edgeapi/response_update_ns_record.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package edgeapi
|
||||||
|
|
||||||
|
type UpdateNSRecordResponse struct {
|
||||||
|
BaseResponse
|
||||||
|
}
|
||||||
@@ -130,14 +130,16 @@ func (this *APINode) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 数据库通知启动
|
// 数据库通知启动
|
||||||
|
this.setProgress("DATABASE", "正在建立数据库模型")
|
||||||
logs.Println("[API_NODE]notify ready ...")
|
logs.Println("[API_NODE]notify ready ...")
|
||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
|
|
||||||
// 设置时区
|
// 设置时区
|
||||||
|
this.setProgress("TIMEZONE", "正在设置时区")
|
||||||
this.setupTimeZone()
|
this.setupTimeZone()
|
||||||
|
|
||||||
// 读取配置
|
// 读取配置
|
||||||
this.setProgress("DATABASE", "加载API配置")
|
this.setProgress("DATABASE", "正在加载API配置")
|
||||||
logs.Println("[API_NODE]reading api config ...")
|
logs.Println("[API_NODE]reading api config ...")
|
||||||
config, err := configs.SharedAPIConfig()
|
config, err := configs.SharedAPIConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -384,6 +386,19 @@ func (this *APINode) setupDB() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否为root用户
|
||||||
|
config, _ := db.Config()
|
||||||
|
if config == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
dsnConfig, err := mysql.ParseDSN(config.Dsn)
|
||||||
|
if err != nil || dsnConfig == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if dsnConfig.User != "root" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 设置Innodb事务提交模式
|
// 设置Innodb事务提交模式
|
||||||
{
|
{
|
||||||
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='innodb_flush_log_at_trx_commit'")
|
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='innodb_flush_log_at_trx_commit'")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package setup
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
@@ -137,12 +138,22 @@ func (this *SQLDump) Dump(db *dbs.DB) (result *SQLDumpResult, err error) {
|
|||||||
func (this *SQLDump) Apply(db *dbs.DB, newResult *SQLDumpResult, showLog bool) (ops []string, err error) {
|
func (this *SQLDump) Apply(db *dbs.DB, newResult *SQLDumpResult, showLog bool) (ops []string, err error) {
|
||||||
// 设置Innodb事务提交模式
|
// 设置Innodb事务提交模式
|
||||||
{
|
{
|
||||||
|
// 检查是否为root用户
|
||||||
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='innodb_flush_log_at_trx_commit'")
|
config, _ := db.Config()
|
||||||
if err == nil && result != nil {
|
if config == nil {
|
||||||
var oldValue = result.GetInt("Value")
|
return nil, nil
|
||||||
if oldValue == 1 {
|
}
|
||||||
_, _ = db.Exec("SET GLOBAL innodb_flush_log_at_trx_commit=2")
|
dsnConfig, err := mysql.ParseDSN(config.Dsn)
|
||||||
|
if err != nil || dsnConfig == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if dsnConfig.User == "root" {
|
||||||
|
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='innodb_flush_log_at_trx_commit'")
|
||||||
|
if err == nil && result != nil {
|
||||||
|
var oldValue = result.GetInt("Value")
|
||||||
|
if oldValue == 1 {
|
||||||
|
_, _ = db.Exec("SET GLOBAL innodb_flush_log_at_trx_commit=2")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func TestSQLDump_Apply(t *testing.T) {
|
|||||||
|
|
||||||
db2, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
db2, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||||
Driver: "mysql",
|
Driver: "mysql",
|
||||||
Dsn: "root:123456@tcp(192.168.2.60:3306)/db_edge_new?charset=utf8mb4&timeout=30s",
|
Dsn: "edge:123456@tcp(192.168.2.60:3306)/db_edge_new?charset=utf8mb4&timeout=30s",
|
||||||
Prefix: "edge",
|
Prefix: "edge",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user