示例#1
0
func getScripts(w http.ResponseWriter, r *http.Request, args []string, user interfaces.User) {
	var scripts []interfaces.Script
	if args[0] == all {
		scripts = user.GetGlobalScripts()
		user.GetNetworks().ForEach(func(net interfaces.Network) {
			scripts = append(scripts, net.GetScripts()...)
		})
	} else if args[0] == global {
		scripts = user.GetGlobalScripts()
	} else {
		net := user.GetNetwork(args[0])
		if net == nil {
			errors.Write(w, errors.NetworkNotFound)
			return
		}
		scripts = net.GetScripts()
	}

	data, err := json.Marshal(scripts)
	if err != nil {
		errors.Write(w, errors.Internal)
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(data)
}