Details fixed about model (#80)
* Details fixed * Fix typo * Clean code
This commit is contained in:
parent
d082b2a2e0
commit
6e17b9a2f1
|
@ -168,9 +168,7 @@ func (l *LogCollect) Encode() error {
|
|||
}
|
||||
|
||||
func (l *LogCollect) Decode() error {
|
||||
var err error
|
||||
|
||||
err = json.Unmarshal([]byte(l.TagsStr), &l.Tags)
|
||||
err := json.Unmarshal([]byte(l.TagsStr), &l.Tags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -192,7 +190,7 @@ func (p *PortCollect) Update() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = session.Id(p.Id).AllCols().Update(p); err != nil {
|
||||
if _, err = session.ID(p.Id).AllCols().Update(p); err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
}
|
||||
|
@ -230,7 +228,7 @@ func (p *ProcCollect) Update() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = session.Id(p.Id).AllCols().Update(p); err != nil {
|
||||
if _, err = session.ID(p.Id).AllCols().Update(p); err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
}
|
||||
|
@ -259,7 +257,7 @@ func GetLogCollects() ([]*LogCollect, error) {
|
|||
return collects, err
|
||||
}
|
||||
|
||||
func (p *LogCollect) Update() error {
|
||||
func (l *LogCollect) Update() error {
|
||||
session := DB["mon"].NewSession()
|
||||
defer session.Close()
|
||||
|
||||
|
@ -268,18 +266,18 @@ func (p *LogCollect) Update() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = session.Id(p.Id).AllCols().Update(p); err != nil {
|
||||
if _, err = session.ID(l.Id).AllCols().Update(l); err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
b, err := json.Marshal(p)
|
||||
b, err := json.Marshal(l)
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
if err := saveHist(p.Id, "log", "update", p.Creator, string(b), session); err != nil {
|
||||
if err := saveHist(l.Id, "log", "update", l.Creator, string(b), session); err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
}
|
||||
|
@ -348,7 +346,7 @@ func GetCollectByNid(collectType string, nids []int64) ([]interface{}, error) {
|
|||
return res, err
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("采集类型不合法")
|
||||
return nil, fmt.Errorf("illegal collectType")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -370,10 +368,8 @@ func GetCollectById(collectType string, cid int64) (interface{}, error) {
|
|||
return collect, err
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("采集类型不合法")
|
||||
return nil, fmt.Errorf("illegal collectType")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func GetCollectByName(collectType string, name string) (interface{}, error) {
|
||||
|
@ -420,15 +416,14 @@ func saveHist(id int64, tp string, action, username, body string, session *xorm.
|
|||
}
|
||||
|
||||
func GetCollectsModel(t string) (interface{}, error) {
|
||||
collects := make([]*PortCollect, 0)
|
||||
switch t {
|
||||
case "port":
|
||||
collects := []*PortCollect{}
|
||||
return collects, nil
|
||||
case "proc":
|
||||
collects := []*ProcCollect{}
|
||||
return collects, nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("采集类型不合法")
|
||||
return nil, fmt.Errorf("illegal collectType")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ func EndpointBindings(endpointIds []int64) ([]EndpointBinding, error) {
|
|||
ret := make([]EndpointBinding, 0, cnt)
|
||||
for i := 0; i < cnt; i++ {
|
||||
nodeids := h2n[endpoints[i].Id]
|
||||
if nodeids == nil || len(nodeids) == 0 {
|
||||
if len(nodeids) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ func NodeGets(where string, args ...interface{}) (nodes []Node, err error) {
|
|||
}
|
||||
|
||||
func NodeGetsByPaths(paths []string) ([]Node, error) {
|
||||
if paths == nil || len(paths) == 0 {
|
||||
if len(paths) == 0 {
|
||||
return []Node{}, nil
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ func (n *Node) Bind(endpointIds []int64, delOld int) error {
|
|||
}
|
||||
|
||||
func (n *Node) Unbind(hostIds []int64) error {
|
||||
if hostIds == nil || len(hostIds) == 0 {
|
||||
if len(hostIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ func NodeIdsGetByEndpointId(endpointId int64) ([]int64, error) {
|
|||
}
|
||||
|
||||
func EndpointIdsByNodeIds(nodeIds []int64) ([]int64, error) {
|
||||
if nodeIds == nil || len(nodeIds) == 0 {
|
||||
if len(nodeIds) == 0 {
|
||||
return []int64{}, nil
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ func EndpointIdsByNodeIds(nodeIds []int64) ([]int64, error) {
|
|||
}
|
||||
|
||||
func NodeEndpointGetByEndpointIds(endpointsIds []int64) ([]NodeEndpoint, error) {
|
||||
if endpointsIds == nil || len(endpointsIds) == 0 {
|
||||
if len(endpointsIds) == 0 {
|
||||
return []NodeEndpoint{}, nil
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ func EndpointBindingsForMail(endpoints []string) []string {
|
|||
}
|
||||
|
||||
func NodeEndpointGetByNodeIds(nodeIds []int64) ([]NodeEndpoint, error) {
|
||||
if nodeIds == nil || len(nodeIds) == 0 {
|
||||
if len(nodeIds) == 0 {
|
||||
return []NodeEndpoint{}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ func (s *Stra) Update() error {
|
|||
return err
|
||||
}
|
||||
|
||||
exists, err := session.Id(s.Id).Get(&obj)
|
||||
exists, err := session.ID(s.Id).Get(&obj)
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
|
@ -142,7 +142,7 @@ func (s *Stra) Update() error {
|
|||
return fmt.Errorf("%d not exists", s.Id)
|
||||
}
|
||||
|
||||
_, err = session.Id(s.Id).AllCols().Update(s)
|
||||
_, err = session.ID(s.Id).AllCols().Update(s)
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
|
@ -187,7 +187,7 @@ func StraDel(id int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
exists, err := session.Id(id).Get(&obj)
|
||||
exists, err := session.ID(id).Get(&obj)
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
|
@ -198,7 +198,7 @@ func StraDel(id int64) error {
|
|||
return fmt.Errorf("%d not exists", obj.Id)
|
||||
}
|
||||
|
||||
if _, err := session.Id(id).Delete(new(Stra)); err != nil {
|
||||
if _, err := session.ID(id).Delete(new(Stra)); err != nil {
|
||||
session.Rollback()
|
||||
return err
|
||||
}
|
||||
|
@ -349,12 +349,16 @@ func (s *Stra) Encode() error {
|
|||
}
|
||||
s.ExprsStr = string(exprs)
|
||||
|
||||
//校验exprs
|
||||
// 校验 exprs
|
||||
var exprsTmp []Exp
|
||||
err = json.Unmarshal(exprs, &exprsTmp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal exprs err:%v", err)
|
||||
}
|
||||
|
||||
for _, exp := range exprsTmp {
|
||||
if _, found := MathOperators[exp.Eopt]; !found {
|
||||
return fmt.Errorf("unknown exp.eopt:%s", exp)
|
||||
return fmt.Errorf("unknown exp.eopt:%v", exp)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,9 +368,13 @@ func (s *Stra) Encode() error {
|
|||
}
|
||||
s.TagsStr = string(tags)
|
||||
|
||||
//校验tags
|
||||
// 校验 tags
|
||||
var tagsTmp []Tag
|
||||
err = json.Unmarshal(tags, &tagsTmp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal Tags err:%v", err)
|
||||
}
|
||||
|
||||
for _, tag := range tagsTmp {
|
||||
if tag.Topt != "=" && tag.Topt != "!=" {
|
||||
return fmt.Errorf("unknown tag.topt")
|
||||
|
@ -470,22 +478,22 @@ func (s *Stra) Decode() error {
|
|||
func checkDurationString(str string) error {
|
||||
slice := strings.Split(str, ":")
|
||||
if len(slice) != 2 {
|
||||
return fmt.Errorf("illegal duration", str)
|
||||
return fmt.Errorf("illegal duration: %s", str)
|
||||
}
|
||||
|
||||
hour, err := strconv.Atoi(slice[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("illegal duration", str)
|
||||
return fmt.Errorf("illegal duration: %s", str)
|
||||
}
|
||||
if hour < 0 || hour > 23 {
|
||||
return fmt.Errorf("illegal duration", str)
|
||||
return fmt.Errorf("illegal duration: %s", str)
|
||||
}
|
||||
minute, err := strconv.Atoi(slice[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("illegal duration", str)
|
||||
return fmt.Errorf("illegal duration: %s", str)
|
||||
}
|
||||
if minute < 0 || minute > 59 {
|
||||
return fmt.Errorf("illegal duration", str)
|
||||
return fmt.Errorf("illegal duration: %s", str)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -131,7 +131,6 @@ func (u *User) CopyLdapAttr(sr *ldap.SearchResult) {
|
|||
if attrs.Im != "" {
|
||||
u.Im = sr.Entries[0].GetAttributeValue(attrs.Im)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func InitRoot() {
|
||||
|
|
|
@ -65,7 +65,7 @@ func GetCachedAll() string {
|
|||
func (this *counterCache) GetKeys() []string {
|
||||
this.RLock()
|
||||
retList := make([]string, 0)
|
||||
for k, _ := range this.Points {
|
||||
for k := range this.Points {
|
||||
retList = append(retList, k)
|
||||
}
|
||||
this.RUnlock()
|
||||
|
@ -89,7 +89,7 @@ func (this *pushPointsCache) AddCounter(counter string) {
|
|||
func (this *pushPointsCache) GetCounters() []string {
|
||||
ret := make([]string, 0)
|
||||
this.RLock()
|
||||
for k, _ := range this.Counters {
|
||||
for k := range this.Counters {
|
||||
ret = append(ret, k)
|
||||
}
|
||||
this.RUnlock()
|
||||
|
|
|
@ -49,7 +49,7 @@ func UpdateConfigsLoop() {
|
|||
}
|
||||
}
|
||||
|
||||
for id, _ := range ManagerConfig {
|
||||
for id := range ManagerConfig {
|
||||
if _, ok := strategyMap[id]; !ok { //如果策略中不存在,说明用户已删除
|
||||
cfg := &ConfigInfo{
|
||||
Id: id,
|
||||
|
|
|
@ -224,7 +224,7 @@ func addFloat64(val *float64, delta float64) (new float64) {
|
|||
func (this *StrategyCounter) GetTmsList() []int64 {
|
||||
tmsList := []int64{}
|
||||
this.RLock()
|
||||
for tms, _ := range this.TmsPoints {
|
||||
for tms := range this.TmsPoints {
|
||||
tmsList = append(tmsList, tms)
|
||||
}
|
||||
this.RUnlock()
|
||||
|
@ -328,7 +328,7 @@ func (this *GlobalCounter) GetStrategyCountByID(id int64) (*StrategyCounter, err
|
|||
func (this *GlobalCounter) GetIDs() []int64 {
|
||||
this.RLock()
|
||||
rList := make([]int64, 0)
|
||||
for k, _ := range this.StrategyCounts {
|
||||
for k := range this.StrategyCounts {
|
||||
rList = append(rList, k)
|
||||
}
|
||||
this.RUnlock()
|
||||
|
|
|
@ -77,6 +77,6 @@ func parseProcName(fname string) (method string, name string, step int, err erro
|
|||
|
||||
method = arr[1]
|
||||
|
||||
name = strings.Join(arr[2:len(arr)], "_")
|
||||
name = strings.Join(arr[2:], "_")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func SplitN(m, n int) [][]int {
|
|||
var res [][]int
|
||||
|
||||
if n <= 0 {
|
||||
return [][]int{[]int{0, m}}
|
||||
return [][]int{{0, m}}
|
||||
}
|
||||
|
||||
for i := 0; i < m; i = i + n {
|
||||
|
|
|
@ -82,7 +82,7 @@ func (n *NodeMap) GetNodes() []string {
|
|||
n.RLock()
|
||||
defer n.RUnlock()
|
||||
var nodes []string
|
||||
for node, _ := range n.data {
|
||||
for node := range n.data {
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
return nodes
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
|
||||
var (
|
||||
validFuncName = map[string]struct{}{
|
||||
"sum": struct{}{},
|
||||
"avg": struct{}{},
|
||||
"max": struct{}{},
|
||||
"min": struct{}{},
|
||||
"sum": {},
|
||||
"avg": {},
|
||||
"max": {},
|
||||
"min": {},
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ func (c *ConnPools) UpdatePools(addrs []string) []string {
|
|||
c.M[addr] = createOnePool(addr, addr, ct, c.MaxConns, c.MaxIdle)
|
||||
}
|
||||
|
||||
for addr, _ := range c.M { //删除旧的地址
|
||||
for addr := range c.M { //删除旧的地址
|
||||
if _, exists := addrMap[addr]; !exists {
|
||||
delete(c.M, addr)
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func RebuildAllIndex(params ...[]string) error {
|
|||
defer UpdateIndexLock.Release()
|
||||
var pushCnt = 0
|
||||
var oldCnt = 0
|
||||
for idx, _ := range IndexedItemCacheBigMap {
|
||||
for idx := range IndexedItemCacheBigMap {
|
||||
keys := IndexedItemCacheBigMap[idx].Keys()
|
||||
|
||||
i := 0
|
||||
|
|
|
@ -44,7 +44,7 @@ func updateIndexIncr() int {
|
|||
ret := 0
|
||||
aggrNum := 200
|
||||
|
||||
for idx, _ := range UnIndexedItemCacheBigMap {
|
||||
for idx := range UnIndexedItemCacheBigMap {
|
||||
if UnIndexedItemCacheBigMap[idx] == nil || UnIndexedItemCacheBigMap[idx].Size() <= 0 {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func SplitN(m, n int) [][]int {
|
|||
var res [][]int
|
||||
|
||||
if n <= 0 {
|
||||
return [][]int{[]int{0, m}}
|
||||
return [][]int{{0, m}}
|
||||
}
|
||||
|
||||
for i := 0; i < m; i = i + n {
|
||||
|
|
Loading…
Reference in New Issue