mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-25 16:11:53 +08:00
Use golint to normalize the code (#1)
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
package cli
|
||||
|
||||
import "math/rand"
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()"
|
||||
|
||||
func genToken() string {
|
||||
b := make([]byte, 8)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
@@ -9,5 +9,5 @@ func InitDB(driver, dsn string) (err error) {
|
||||
case "sqlite":
|
||||
DB, err = NewSqlite3(dsn)
|
||||
}
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ func (f *MapField) Scan(data interface{}) error {
|
||||
return json.Unmarshal(data.([]byte), f)
|
||||
}
|
||||
|
||||
|
||||
type ListField []string
|
||||
|
||||
func (f ListField) Value() (driver.Value, error) {
|
||||
@@ -24,4 +23,4 @@ func (f ListField) Value() (driver.Value, error) {
|
||||
|
||||
func (f *ListField) Scan(data interface{}) error {
|
||||
return json.Unmarshal(data.([]byte), f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ func Accept(logger Logger) dns.MsgAcceptFunc {
|
||||
return func(dh dns.Header) dns.MsgAcceptAction {
|
||||
// check if request
|
||||
if dh.Bits&(1<<15) != 0 {
|
||||
log(logger, Ignored, nil, nil, fmt.Sprintf("not a request"))
|
||||
log(logger, Ignored, nil, nil, "not a request")
|
||||
return dns.MsgIgnore
|
||||
}
|
||||
|
||||
// check opcode
|
||||
if int(dh.Bits>>11)&0xF != dns.OpcodeQuery {
|
||||
log(logger, Ignored, nil, nil, fmt.Sprintf("not a query"))
|
||||
log(logger, Ignored, nil, nil, "not a query")
|
||||
return dns.MsgIgnore
|
||||
}
|
||||
|
||||
|
||||
@@ -272,7 +272,7 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
|
||||
|
||||
// Close will close the server.
|
||||
func (s *Server) Close() {
|
||||
defer func() { recover() }()
|
||||
defer func() { recover() }() // nolint:errcheck
|
||||
close(s.close)
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ func (z *Zone) Lookup(name, remoteAddr string, needle ...Type) ([]Set, bool, err
|
||||
|
||||
for i := 0; ; i++ {
|
||||
// get sets
|
||||
sets, err := z.Handler(TrimZone(z.Name, name),remoteAddr)
|
||||
sets, err := z.Handler(TrimZone(z.Name, name), remoteAddr)
|
||||
if err != nil {
|
||||
return nil, false, errors.Wrap(err, "zone handler error")
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func TestZoneLookup(t *testing.T) {
|
||||
"ns1.example.com.",
|
||||
"ns2.example.com.",
|
||||
},
|
||||
Handler: func(name,remoteAddr string) ([]Set, error) {
|
||||
Handler: func(name, remoteAddr string) ([]Set, error) {
|
||||
if name == "error" {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/li4n0/revsuit/internal/record"
|
||||
)
|
||||
|
||||
func formatRecordField(r record.Record,fieldFormat string) (content string) {
|
||||
func formatRecordField(r record.Record, fieldFormat string) (content string) {
|
||||
structType := reflect.ValueOf(r)
|
||||
for i := 0; i < structType.NumField(); i++ {
|
||||
structField := structType.Type().Field(i)
|
||||
@@ -27,6 +27,6 @@ func formatRecordField(r record.Record,fieldFormat string) (content string) {
|
||||
}
|
||||
content += fmt.Sprintf(fieldFormat+"\n", strings.ToUpper(fieldName), value)
|
||||
}
|
||||
strings.TrimSuffix(content, "\n")
|
||||
return
|
||||
content = strings.TrimSuffix(content, "\n")
|
||||
return content
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type larkElement struct {
|
||||
}
|
||||
|
||||
type larkCard struct {
|
||||
Header larkHeader `json:"header"`
|
||||
Header larkHeader `json:"header"`
|
||||
Elements []larkElement `json:"elements"`
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ func (d *Lark) buildPayload(r record.Record) string {
|
||||
payload := larkPayload{
|
||||
MsgType: "interactive",
|
||||
Card: larkCard{
|
||||
Header:larkHeader{
|
||||
Header: larkHeader{
|
||||
Title: larkText{
|
||||
Tag: "plain_text",
|
||||
Tag: "plain_text",
|
||||
Content: "New Connection",
|
||||
},
|
||||
},
|
||||
@@ -55,7 +55,7 @@ func (d *Lark) buildPayload(r record.Record) string {
|
||||
Tag: "div",
|
||||
Text: larkText{
|
||||
Tag: "lark_md",
|
||||
Content: formatRecordField(r,"**%s**: %v"),
|
||||
Content: formatRecordField(r, "**%s**: %v"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -27,7 +27,7 @@ type slackBlock struct {
|
||||
}
|
||||
|
||||
type slackAttachments struct {
|
||||
Color string `json:"color"`
|
||||
Color string `json:"color"`
|
||||
Blocks []slackBlock `json:"blocks"`
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ func get(url string) (b []byte, err error) {
|
||||
defer resp.Body.Close()
|
||||
|
||||
b, err = ioutil.ReadAll(resp.Body)
|
||||
return
|
||||
return b, err
|
||||
}
|
||||
|
||||
func getKey(b []byte) (key uint32, err error) {
|
||||
@@ -43,7 +43,7 @@ func getKey(b []byte) (key uint32, err error) {
|
||||
return 0, errors.New("copywrite.rar is corrupt")
|
||||
}
|
||||
key = binary.LittleEndian.Uint32(b[20:])
|
||||
return
|
||||
return key, err
|
||||
}
|
||||
|
||||
func decrypt(b []byte, key uint32) (_ []byte, err error) {
|
||||
|
||||
@@ -21,7 +21,7 @@ func init() {
|
||||
log.Error("Download qqwry.dat failed, caused by:%v, recommend to download it by yourself otherwise the `IpArea` will be null", err.Error())
|
||||
}
|
||||
}
|
||||
} else if info.ModTime().Sub(time.Now()) > 5*24*time.Hour {
|
||||
} else if time.Until(info.ModTime()) > 5*24*time.Hour {
|
||||
log.Info("Updating qqwry.dat...")
|
||||
err := download()
|
||||
if err != nil {
|
||||
|
||||
@@ -61,5 +61,5 @@ func (br BaseRule) Match(s string) (flag, flagGroup string) {
|
||||
flagGroup = matched[1]
|
||||
}
|
||||
}
|
||||
return
|
||||
return flag, flagGroup
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user