func (c ec2Instances) Get(session *util.Session, url string, queries url.Values, body io.Reader) (util.APIStatus, interface{}) { if misc.ZeroOrNil(session) || misc.ZeroOrNil(session.UserID) { return util.FailSimple(http.StatusUnauthorized), nil } instances, _ := models.GetEC2Instances() return util.Success(http.StatusOK), struct { EC2Instances []*models.EC2Instance `json:"instances"` Count int `json:"count"` }{ EC2Instances: instances, Count: len(instances), } }
func header(r *http.Request, key string) (string, bool) { if r.Header == nil { return "", false } if candidate := r.Header[key]; !misc.ZeroOrNil(candidate) { return candidate[0], true } return "", false }
func (config *Config) complete() bool { cfgs := reflect.ValueOf(config).Elem() for i := 0; i < cfgs.NumField(); i++ { if misc.ZeroOrNil(cfgs.Field(i).Interface()) { return false } } return true }
func (config *Config) merge(arg Config) *Config { mine := reflect.ValueOf(config).Elem() theirs := reflect.ValueOf(&arg).Elem() for i := 0; i < mine.NumField(); i++ { myField := mine.Field(i) if misc.ZeroOrNil(myField.Interface()) { myField.Set(reflect.ValueOf(theirs.Field(i).Interface())) } } return config }
func toStringArray(values string) []string { if misc.ZeroOrNil(values) { return []string{} } return strings.Split(values, ",") }