Example #1
0
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),
	}
}
Example #2
0
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
}
Example #3
0
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
}
Example #4
0
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
}
Example #5
0
func toStringArray(values string) []string {
	if misc.ZeroOrNil(values) {
		return []string{}
	}
	return strings.Split(values, ",")
}