mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	更新TeaGo
This commit is contained in:
		
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@@ -12,7 +12,7 @@ require (
 | 
			
		||||
	github.com/go-acme/lego/v4 v4.5.2
 | 
			
		||||
	github.com/go-sql-driver/mysql v1.5.0
 | 
			
		||||
	github.com/golang/protobuf v1.5.2
 | 
			
		||||
	github.com/iwind/TeaGo v0.0.0-20220322141208-22f88d04004d
 | 
			
		||||
	github.com/iwind/TeaGo v0.0.0-20220408064305-92be81dc2f7c
 | 
			
		||||
	github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3
 | 
			
		||||
	github.com/json-iterator/go v1.1.12 // indirect
 | 
			
		||||
	github.com/mozillazg/go-pinyin v0.18.0
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							@@ -240,6 +240,8 @@ github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7Q
 | 
			
		||||
github.com/iwind/TeaGo v0.0.0-20220304043459-0dd944a5b475/go.mod h1:HRHK0zoC/og3c9/hKosD9yYVMTnnzm3PgXUdhRYHaLc=
 | 
			
		||||
github.com/iwind/TeaGo v0.0.0-20220322141208-22f88d04004d h1:e8fkTKras/RXQWECApM9fKlFWujjYjEClpshkmZmtYg=
 | 
			
		||||
github.com/iwind/TeaGo v0.0.0-20220322141208-22f88d04004d/go.mod h1:HRHK0zoC/og3c9/hKosD9yYVMTnnzm3PgXUdhRYHaLc=
 | 
			
		||||
github.com/iwind/TeaGo v0.0.0-20220408064305-92be81dc2f7c h1:ugjYZ74FJGWlfDKKraNgMyDTeS4vbXHe89JGUVQIJMo=
 | 
			
		||||
github.com/iwind/TeaGo v0.0.0-20220408064305-92be81dc2f7c/go.mod h1:HRHK0zoC/og3c9/hKosD9yYVMTnnzm3PgXUdhRYHaLc=
 | 
			
		||||
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3 h1:aBSonas7vFcgTj9u96/bWGILGv1ZbUSTLiOzcI1ZT6c=
 | 
			
		||||
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA=
 | 
			
		||||
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ func (this *HTTPAccessLogManager) FindTableNames(db *dbs.DB, day string) ([]stri
 | 
			
		||||
 | 
			
		||||
	// 需要防止用户设置了表名自动小写
 | 
			
		||||
	for _, prefix := range []string{"edgeHTTPAccessLogs_" + day + "%", "edgehttpaccesslogs_" + day + "%"} {
 | 
			
		||||
		ones, columnNames, err := db.FindOnes(`SHOW TABLES LIKE '` + prefix + `'`)
 | 
			
		||||
		ones, columnNames, err := db.FindPreparedOnes(`SHOW TABLES LIKE '` + prefix + `'`)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, errors.New("query table names error: " + err.Error())
 | 
			
		||||
		}
 | 
			
		||||
@@ -77,9 +77,15 @@ func (this *HTTPAccessLogManager) FindTables(db *dbs.DB, day string) ([]*httpAcc
 | 
			
		||||
	var results = []*httpAccessLogDefinition{}
 | 
			
		||||
	var tableNames = []string{}
 | 
			
		||||
 | 
			
		||||
	config, err := db.Config()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var cachePrefix = config.Dsn
 | 
			
		||||
 | 
			
		||||
	// 需要防止用户设置了表名自动小写
 | 
			
		||||
	for _, prefix := range []string{"edgeHTTPAccessLogs_" + day + "%", "edgehttpaccesslogs_" + day + "%"} {
 | 
			
		||||
		ones, columnNames, err := db.FindOnes(`SHOW TABLES LIKE '` + prefix + `'`)
 | 
			
		||||
		ones, columnNames, err := db.FindPreparedOnes(`SHOW TABLES LIKE '` + prefix + `'`)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, errors.New("query table names error: " + err.Error())
 | 
			
		||||
		}
 | 
			
		||||
@@ -96,17 +102,26 @@ func (this *HTTPAccessLogManager) FindTables(db *dbs.DB, day string) ([]*httpAcc
 | 
			
		||||
			if accessLogTableMainReg.MatchString(tableName) {
 | 
			
		||||
				tableNames = append(tableNames, tableName)
 | 
			
		||||
 | 
			
		||||
				hasRemoteAddrField, hasDomainField, err := this.checkTableFields(db, tableName)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return nil, err
 | 
			
		||||
				}
 | 
			
		||||
				var tableDay = tableName[strings.LastIndex(tableName, "_")+1:]
 | 
			
		||||
				var cacheKey = this.composeTableCacheKey(cachePrefix, tableDay)
 | 
			
		||||
				this.locker.Lock()
 | 
			
		||||
				currentTableDef, ok := this.currentTableMapping[cacheKey]
 | 
			
		||||
				this.locker.Unlock()
 | 
			
		||||
				if ok {
 | 
			
		||||
					results = append(results, currentTableDef)
 | 
			
		||||
				} else {
 | 
			
		||||
					hasRemoteAddrField, hasDomainField, err := this.checkTableFields(db, tableName)
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						return nil, err
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
				results = append(results, &httpAccessLogDefinition{
 | 
			
		||||
					Name:          tableName,
 | 
			
		||||
					HasRemoteAddr: hasRemoteAddrField,
 | 
			
		||||
					HasDomain:     hasDomainField,
 | 
			
		||||
					Exists:        true,
 | 
			
		||||
				})
 | 
			
		||||
					results = append(results, &httpAccessLogDefinition{
 | 
			
		||||
						Name:          tableName,
 | 
			
		||||
						HasRemoteAddr: hasRemoteAddrField,
 | 
			
		||||
						HasDomain:     hasDomainField,
 | 
			
		||||
						Exists:        true,
 | 
			
		||||
					})
 | 
			
		||||
				}
 | 
			
		||||
			} else if accessLogTablePartialReg.MatchString(tableName) {
 | 
			
		||||
				tableNames = append(tableNames, tableName)
 | 
			
		||||
 | 
			
		||||
@@ -296,7 +311,7 @@ func (this *HTTPAccessLogManager) findTableWithoutCache(db *dbs.DB, day string,
 | 
			
		||||
 | 
			
		||||
// TODO 考虑缓存检查结果
 | 
			
		||||
func (this *HTTPAccessLogManager) checkTableFields(db *dbs.DB, tableName string) (hasRemoteAddrField bool, hasDomainField bool, err error) {
 | 
			
		||||
	fields, _, err := db.FindOnes("SHOW FIELDS FROM " + tableName)
 | 
			
		||||
	fields, _, err := db.FindPreparedOnes("SHOW FIELDS FROM " + tableName)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return false, false, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -585,6 +585,8 @@ func (this *APINode) listenSock() error {
 | 
			
		||||
				_ = cmd.Reply(&gosock.Command{
 | 
			
		||||
					Params: map[string]interface{}{"debug": teaconst.Debug},
 | 
			
		||||
				})
 | 
			
		||||
			case "db.stmt":
 | 
			
		||||
				dbs.ShowPreparedStatements = true
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,7 @@ func (this *DBService) FindAllDBTables(ctx context.Context, req *pb.FindAllDBTab
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	ones, _, err := db.FindOnes("SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA=?", db.Name())
 | 
			
		||||
	ones, _, err := db.FindPreparedOnes("SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA=?", db.Name())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -199,7 +199,7 @@ func (this *DBNodeService) FindAllDBNodeTables(ctx context.Context, req *pb.Find
 | 
			
		||||
		_ = db.Close()
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	ones, _, err := db.FindOnes("SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA=?", db.Name())
 | 
			
		||||
	ones, _, err := db.FindPreparedOnes("SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA=?", db.Name())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ func TestDBService_FindAllDBTables(t *testing.T) {
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	ones, _, err := db.FindOnes("SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA=?", db.Name())
 | 
			
		||||
	ones, _, err := db.FindPreparedOnes("SELECT * FROM information_schema.`TABLES` WHERE TABLE_SCHEMA=?", db.Name())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -104,7 +104,7 @@ func (this *ServerAccessLogCleaner) Loop() error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *ServerAccessLogCleaner) cleanDB(db *dbs.DB, endDay string) error {
 | 
			
		||||
	ones, columnNames, err := db.FindOnes("SHOW TABLES")
 | 
			
		||||
	ones, columnNames, err := db.FindPreparedOnes("SHOW TABLES")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user