update
This commit is contained in:
+83
-12
@@ -1,5 +1,13 @@
|
|||||||
package qinglong
|
package qinglong
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cdle/sillyGirl/core"
|
||||||
|
"github.com/cdle/sillyGirl/im"
|
||||||
|
)
|
||||||
|
|
||||||
type EnvResponse struct {
|
type EnvResponse struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Data []Env `json:"data"`
|
Data []Env `json:"data"`
|
||||||
@@ -14,6 +22,69 @@ type Env struct {
|
|||||||
Remarks string `json:"remarks,omitempty"`
|
Remarks string `json:"remarks,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
core.AddCommand([]core.Function{
|
||||||
|
{
|
||||||
|
Rules: []string{`^env\s+get\s+([\S]*)$`},
|
||||||
|
Handle: func(s im.Sender) interface{} {
|
||||||
|
m := s.Get()
|
||||||
|
env, err := GetEnv(m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if env == nil {
|
||||||
|
return "未设置该环境变量"
|
||||||
|
}
|
||||||
|
if env != nil {
|
||||||
|
return formatEnv(env)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Rules: []string{`^env\s+find\s+([\S]*)$`},
|
||||||
|
Handle: func(s im.Sender) interface{} {
|
||||||
|
m := s.Get()
|
||||||
|
envs, err := GetEnvs(m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(envs) == 0 {
|
||||||
|
return "未设置该环境变量"
|
||||||
|
}
|
||||||
|
es := []string{}
|
||||||
|
for _, env := range envs {
|
||||||
|
es = append(es, formatEnv(&env))
|
||||||
|
}
|
||||||
|
return strings.Join(es, "\n\n")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Rules: []string{`^export\s+([^'"=]+)=['"]?([^=]+?)['"]?$`, `^env\s+set\s+([^'"=]+)=['"]?([^=]+?)['"]?$`},
|
||||||
|
Handle: func(s im.Sender) interface{} {
|
||||||
|
e := &Env{
|
||||||
|
Name: s.Get(0),
|
||||||
|
Value: s.Get(1),
|
||||||
|
}
|
||||||
|
err := SetEnv(e)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("操作成功")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Rules: []string{`^env\s+del\s+([\S]*)$`},
|
||||||
|
Handle: func(s im.Sender) interface{} {
|
||||||
|
if err := RemEnv(&Env{ID: s.Get()}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return "操作成功"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func GetEnv(searchValue string) (*Env, error) {
|
func GetEnv(searchValue string) (*Env, error) {
|
||||||
envs, err := GetEnvs(searchValue)
|
envs, err := GetEnvs(searchValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -51,16 +122,16 @@ func AddEnv(e *Env) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RemEnv(e *Env) error {
|
func RemEnv(e *Env) error {
|
||||||
es, err := GetEnvs(e.Name)
|
return req(DELETE, ENVS, []byte(`["`+e.ID+`"]`))
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
func formatEnv(env *Env) string {
|
||||||
if len(es) == 0 {
|
status := "已启用"
|
||||||
return nil
|
if env.Status != 0 {
|
||||||
}
|
status = "已禁用"
|
||||||
td := []string{}
|
}
|
||||||
for _, e := range es {
|
if env.Remarks == "" {
|
||||||
td = append(td, e.ID)
|
env.Remarks = "无"
|
||||||
}
|
}
|
||||||
return req(DELETE, ENVS, td)
|
return fmt.Sprintf("名称:%v\n编号:%v\n备注:%v\n状态:%v\n时间:%v\n值:%v", env.Name, env.ID, env.Remarks, status, env.Timestamp, env.Value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/buger/jsonparser"
|
"github.com/buger/jsonparser"
|
||||||
"github.com/cdle/sillyGirl/core"
|
"github.com/cdle/sillyGirl/core"
|
||||||
"github.com/cdle/sillyGirl/im"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Yaml struct {
|
type Yaml struct {
|
||||||
@@ -37,64 +36,6 @@ func init() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
logs.Info("青龙已连接")
|
logs.Info("青龙已连接")
|
||||||
}
|
}
|
||||||
core.AddCommand([]core.Function{
|
|
||||||
{
|
|
||||||
Rules: []string{`^env\s+get\s+([\S]*)$`},
|
|
||||||
Handle: func(s im.Sender) interface{} {
|
|
||||||
m := s.Get()
|
|
||||||
env, err := GetEnv(m)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if env == nil {
|
|
||||||
return "未设置该环境变量"
|
|
||||||
}
|
|
||||||
if env != nil {
|
|
||||||
status := "已启用"
|
|
||||||
if env.Status != 0 {
|
|
||||||
status = "已禁用"
|
|
||||||
}
|
|
||||||
if env.Remarks == "" {
|
|
||||||
env.Remarks = "无"
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("名称:%v\n备注:%v\n状态:%v\n时间:%v\n值:%v", env.Name, env.Remarks, status, env.Timestamp, env.Value)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Rules: []string{`^env\s+find\s+([\S]*)$`},
|
|
||||||
Handle: func(s im.Sender) interface{} {
|
|
||||||
m := s.Get()
|
|
||||||
envs, err := GetEnvs(m)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(envs) == 0 {
|
|
||||||
return "未设置该环境变量"
|
|
||||||
}
|
|
||||||
es := []string{}
|
|
||||||
for _, env := range envs {
|
|
||||||
es = append(es, env.Value)
|
|
||||||
}
|
|
||||||
return strings.Join(es, "\n")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Rules: []string{`^export\s+([^'"=]+)=['"]?([^=]+?)['"]?$`, `^env\s+set\s+([^'"=]+)=['"]?([^=]+?)['"]?$`},
|
|
||||||
Handle: func(s im.Sender) interface{} {
|
|
||||||
e := &Env{
|
|
||||||
Name: s.Get(0),
|
|
||||||
Value: s.Get(1),
|
|
||||||
}
|
|
||||||
err := SetEnv(e)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("操作成功")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getToken() (string, error) {
|
func getToken() (string, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user