示例#1
0
文件: widgets.go 项目: murdinc/awsm
func getFeed(w http.ResponseWriter, r *http.Request) {
	feedName := chi.URLParam(r, "feedName")

	feedSettings, err := config.LoadWidget(feedName)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	var items config.FeedItems

	feed, err := rss.Fetch(feedSettings.RssURL)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	for _, i := range feed.Items {
		items.ParseItem(i)
	}

	items, err = config.SaveFeed(feedName, items, feedSettings.Count)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"feed": items, "success": true})
}
示例#2
0
文件: widgets.go 项目: murdinc/awsm
func getEvents(w http.ResponseWriter, r *http.Request) {
	events, err := aws.GetEvents()
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"events": events, "success": true})
}
示例#3
0
文件: widgets.go 项目: murdinc/awsm
func getWidgetNames(w http.ResponseWriter, r *http.Request) {
	resp, err := config.LoadAllWidgetNames()

	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"widgetNames": resp, "success": true})
}
示例#4
0
文件: widgets.go 项目: murdinc/awsm
func deleteWidget(w http.ResponseWriter, r *http.Request) {
	widgetName := chi.URLParam(r, "widgetName")

	err := config.DeleteWidget(widgetName)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"success": true})
}
示例#5
0
文件: classes.go 项目: murdinc/awsm
func getClassNames(w http.ResponseWriter, r *http.Request) {
	classType := chi.URLParam(r, "classType")
	resp, err := config.LoadAllClassNames(classType)

	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"classType": classType, "classNames": resp, "success": true})
}
示例#6
0
文件: classes.go 项目: murdinc/awsm
func exportClasses(w http.ResponseWriter, r *http.Request) {

	resp, err := config.Export()

	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"classes": resp, "success": true})
}
示例#7
0
文件: widgets.go 项目: murdinc/awsm
func putWidget(w http.ResponseWriter, r *http.Request) {
	widgetName := chi.URLParam(r, "widgetName")

	data, err := ioutil.ReadAll(r.Body)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{"Error Reading Body!", err.Error()}})
		return
	}

	// check for empty body?
	if len(data) == 0 {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{"No widget object was passed!"}})
		return
	}

	widget, err := config.SaveWidget(widgetName, data)

	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{"Error saving Class!", err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"widget": widget, "success": true})
}
示例#8
0
文件: index.go 项目: zqzca/back
// Index returns a list of files
func (c Controller) Index(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
	perPage := ctx.Value(1001).(int)
	page := ctx.Value(1002).(int)

	entries, err := pagination(c.DB, page, perPage)

	if err != nil {
		c.Error("failed to fetch page:", "err", err)
		http.Error(w, http.StatusText(500), 500)
		return
	}

	total := totalPages(c.DB, perPage)

	data := dashboardData{
		Entries: entries,
		Total:   total,
		Page:    page,
	}

	render.JSON(w, r, data)
}
示例#9
0
文件: widgets.go 项目: murdinc/awsm
func getWidgetOptions(w http.ResponseWriter, r *http.Request) {
	resp := make(map[string][]string)
	resp["availableWidgets"] = []string{"events", "alarms", "rss"}
	render.JSON(w, r, map[string]interface{}{"options": resp, "success": true})
}
示例#10
0
文件: classes.go 项目: murdinc/awsm
func putClass(w http.ResponseWriter, r *http.Request) {
	classType := chi.URLParam(r, "classType")
	className := chi.URLParam(r, "className")

	data, err := ioutil.ReadAll(r.Body)
	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{"Error Reading Body!", err.Error()}})
		return
	}

	// check for empty body?
	if len(data) == 0 {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{"No class object was passed!"}})
		return
	}

	var class interface{}

	switch classType {

	case "vpcs":
		class, err = config.SaveVpcClass(className, data)

	case "subnets":
		class, err = config.SaveSubnetClass(className, data)

	case "instances":
		class, err = config.SaveInstanceClass(className, data)

	case "volumes":
		class, err = config.SaveVolumeClass(className, data)

	case "snapshots":
		class, err = config.SaveSnapshotClass(className, data)

	case "images":
		class, err = config.SaveImageClass(className, data)

	case "autoscalegroups":
		class, err = config.SaveAutoscalingGroupClass(className, data)

	case "launchconfigurations":
		class, err = config.SaveLaunchConfigurationClass(className, data)

	case "loadbalancers":
		class, err = config.SaveLoadBalancerClass(className, data)

	case "scalingpolicies":
		class, err = config.SaveScalingPolicyClass(className, data)

	case "alarms":
		class, err = config.SaveAlarmClass(className, data)

	case "securitygroups":
		class, err = config.SaveSecurityGroupClass(className, data)

	case "keypairs":
		class, err = config.SaveKeyPairClass(className, data)

	}

	if err != nil {
		render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{"Error saving Class!", err.Error()}})
		return
	}

	render.JSON(w, r, map[string]interface{}{"classType": classType, "class": class, "success": true})
}
示例#11
0
文件: assets.go 项目: murdinc/awsm
func getAssets(w http.ResponseWriter, r *http.Request) {
	// Get the listType
	assetType := chi.URLParam(r, "assetType")

	var resp interface{}
	var errs []error // multi-region
	var err error    // single region

	switch assetType {

	case "addresses":
		resp, errs = aws.GetAddresses("", false)

	case "alarms":
		resp, errs = aws.GetAlarms()

	case "autoscalegroups":
		resp, errs = aws.GetAutoScaleGroups("")

	case "iamusers":
		resp, err = aws.GetIAMUsers("")

	case "images":
		resp, errs = aws.GetImages("", false)

	case "instances":
		resp, errs = aws.GetInstances("", false)

	case "keypairs":
		resp, errs = aws.GetKeyPairs("")

	case "launchconfigurations":
		resp, errs = aws.GetLaunchConfigurations("")

	case "loadbalancers":
		resp, errs = aws.GetLoadBalancers()

	case "scalingpolicies":
		resp, errs = aws.GetScalingPolicies()

	case "securitygroups":
		resp, errs = aws.GetSecurityGroups("")

	case "simpledbdomains":
		resp, errs = aws.GetSimpleDBDomains("")

	case "snapshots":
		resp, errs = aws.GetSnapshots("", false)

	case "subnets":
		resp, errs = aws.GetSubnets("")

	case "volumes":
		resp, errs = aws.GetVolumes("", false)

	case "vpcs":
		resp, errs = aws.GetVpcs("")

		/*
			case "buckets": // TODO
				resp, errs = aws.GetBuckets()
		*/

	default:
		err = errors.New("Unknown list type")
	}

	// Combine errors
	if err != nil {
		errs = append(errs, err)
	}

	if len(errs) == 0 {
		render.JSON(w, r, map[string]interface{}{"assetType": assetType, "assets": resp, "success": true})
	} else {

		errStrs := make([]string, len(errs))

		for i, e := range errs {
			errStrs[i] = e.Error()
		}

		render.JSON(w, r, map[string]interface{}{"assetType": assetType, "assets": resp, "success": false, "errors": errStrs})
	}
}