func NewProfileClient(filepath string) (client *Client, err error) { client = new(Client) jsonstream, err := ioutil.ReadFile(filepath) if err != nil { return nil, err } if err := json.Unmarshal(jsonstream, client); err != nil { return nil, err } if client.Id == "" { client.Id = uuid.New() } if client.RegTime.IsZero() { client.RegTime = time.Now() } if client.Apps == nil { client.Apps = []string{} } client.Skip_work = []string{} client.Status = "active" if client.Current_work == nil { client.Current_work = map[string]bool{} } client.Tag = true return }
func NewProfileClient(filepath string) (client *Client, err error) { client = new(Client) jsonstream, err := ioutil.ReadFile(filepath) if err != nil { return nil, err } if err := json.Unmarshal(jsonstream, client); err != nil { logger.Error("failed to unmashal json stream for client profile: " + string(jsonstream[:])) return nil, err } if client.Id == "" { client.Id = uuid.New() } if client.RegTime.IsZero() { client.RegTime = time.Now() } if client.Apps == nil { client.Apps = []string{} } client.Skip_work = []string{} client.Status = CLIENT_STAT_ACTIVE_IDLE if client.Current_work == nil { client.Current_work = map[string]bool{} } client.Tag = true return }
func CreateClientGroup(name string, u *user.User) (cg *ClientGroup, err error) { q := bson.M{"name": name} clientgroups := new(ClientGroups) if count, err := dbFindClientGroups(q, clientgroups); err != nil { return nil, err } else if count > 0 { return nil, errors.New("A clientgroup already exists with this name.") } if !CGNameRegex.Match([]byte(name)) { return nil, errors.New(fmt.Sprintf("Clientgroup name (%s) must contain only alphanumeric characters, underscore, dash or dot.", name)) } t := time.Now() cg = new(ClientGroup) cg.Id = uuid.New() cg.IP_CIDR = "0.0.0.0/0" cg.Name = name cg.Expiration = t.AddDate(10, 0, 0) cg.Acl.SetOwner(u.Uuid) cg.Acl.Set(u.Uuid, clientGroupAcl.Rights{"read": true, "write": true, "delete": true, "execute": true}) cg.CreatedOn = t cg.SetToken() if err = cg.Save(); err != nil { err = errors.New("error in cg.Save(), error=" + err.Error()) return } return }
func NewClient() (client *Client) { client = new(Client) client.Id = uuid.New() client.Apps = []string{} client.Skip_work = []string{} client.Status = CLIENT_STAT_ACTIVE client.Total_checkout = 0 client.Total_completed = 0 client.Total_failed = 0 client.Current_work = map[string]bool{} client.Tag = true client.Serve_time = "0" client.Last_failed = 0 return }
//set job's uuid func (job *Job) setId() { job.Id = uuid.New() return }