mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-26 16:41:53 +08:00
feat(ftp): support receive ftp connection (#6)
Co-authored-by: E99p1ant <[email protected]>
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func NewSqlite3(dsn string) (*gorm.DB, error) {
|
||||
if strings.Contains(dsn, "?") {
|
||||
dsn += "&_synchronous=1&_journal_mode=WAL"
|
||||
} else {
|
||||
dsn += "?_synchronous=1&_journal_mode=WAL"
|
||||
}
|
||||
|
||||
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package qqwry
|
||||
|
||||
// Area return IpArea according to ip
|
||||
// Area returns IpArea according to ip
|
||||
func Area(ip string) string {
|
||||
defer func() {
|
||||
_ = recover()
|
||||
}()
|
||||
if GetQQWry() == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package rule
|
||||
|
||||
import "strings"
|
||||
|
||||
func CompileTpl(tpl string, vars map[string]string) (compiled string) {
|
||||
compiled = tpl
|
||||
for n, v := range vars {
|
||||
compiled = strings.ReplaceAll(compiled, "${"+n+"}", v)
|
||||
}
|
||||
|
||||
return compiled
|
||||
}
|
||||
+15
-3
@@ -2,6 +2,7 @@ package rule
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "unknwon.dev/clog/v2"
|
||||
@@ -25,7 +26,9 @@ type BaseRule struct {
|
||||
Notice bool `gorm:"default:false;not null;" form:"notice" json:"notice"`
|
||||
}
|
||||
|
||||
func (br BaseRule) Match(s string) (flag, flagGroup string) {
|
||||
func (br BaseRule) Match(s string) (flag, flagGroup string, vars map[string]string) {
|
||||
vars = make(map[string]string)
|
||||
|
||||
if br.flagCatcher == nil {
|
||||
if br.FlagFormat == "*" {
|
||||
flag = "*"
|
||||
@@ -41,13 +44,22 @@ func (br BaseRule) Match(s string) (flag, flagGroup string) {
|
||||
}
|
||||
|
||||
matched := br.flagCatcher.FindStringSubmatch(s)
|
||||
groupNames := br.flagCatcher.SubexpNames()
|
||||
|
||||
if len(matched) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
flag = matched[0]
|
||||
if len(matched) > 1 {
|
||||
if len(matched) > 1 && len(groupNames) == 0 {
|
||||
flagGroup = matched[1]
|
||||
}
|
||||
return flag, flagGroup
|
||||
|
||||
for j, name := range groupNames {
|
||||
if j != 0 && name != "" {
|
||||
vars[name] = strings.TrimSpace(matched[j])
|
||||
}
|
||||
}
|
||||
|
||||
return flag, flagGroup, vars
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user