Пример #1
0
//GetDefinitionList returns a list of server definitions
func (ServerDef) GetDefinitionList(kvs kvstore.KVStore, resp http.ResponseWriter, req *http.Request) (interface{}, error) {

	servers, err := config.ListServerConfigs(kvs)
	if err != nil {
		resp.WriteHeader(http.StatusInternalServerError)
		return nil, err
	}

	if servers == nil {
		servers = make([]*config.ServerConfig, 0)
	}

	return servers, nil

}
Пример #2
0
//Run executes the ServerList command with the supplied args
func (sl *ServerList) Run(args []string) int {
	servers, err := config.ListServerConfigs(sl.KVStore)
	if err != nil {
		sl.UI.Error(err.Error())
		return 1
	}

	jsonRep, err := json.Marshal(servers)
	if err != nil {
		sl.UI.Error(err.Error())
		return 1
	}

	if bytes.Equal(jsonRep, config.NullJSON) {
		sl.UI.Output("[]")
	} else {
		sl.UI.Output(string(jsonRep))
	}

	return 0
}