当前位置: 首页>>代码示例>>Golang>>正文


Golang goweb.Context类代码示例

本文整理汇总了Golang中github.com/jaredwilkening/goweb.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ReadMany

// GET: /user
func (cr *UserController) ReadMany(cx *goweb.Context) {
	// Log Request and check for Auth
	LogRequest(cx.Request)
	u, err := AuthenticateRequest(cx.Request)
	if err != nil {
		if err.Error() == e.NoAuth || err.Error() == e.UnAuth {
			cx.RespondWithError(http.StatusUnauthorized)
			return
		} else {
			log.Error("[email protected]_Read: " + err.Error())
			cx.RespondWithError(http.StatusInternalServerError)
			return
		}
	}
	if u.Admin {
		users := user.Users{}
		user.AdminGet(&users)
		if len(users) > 0 {
			cx.RespondWithData(users)
			return
		} else {
			cx.RespondWithNotFound()
			return
		}
	} else {
		cx.RespondWithError(http.StatusUnauthorized)
		return
	}
}
开发者ID:eberroca,项目名称:Shock,代码行数:30,代码来源:userController.go

示例2: Read

// GET: /client/{id}
func (cr *ClientController) Read(id string, cx *goweb.Context) {
	LogRequest(cx.Request)

	// Gather query params
	query := &Query{list: cx.Request.URL.Query()}
	if query.Has("heartbeat") {
		client, err := queueMgr.ClientHeartBeat(id)
		if err != nil {
			cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
		} else {
			cx.RespondWithData(client.Id)
		}
		return
	}

	client, err := queueMgr.GetClient(id)
	if err != nil {
		if err.Error() == e.ClientNotFound {
			cx.RespondWithErrorMessage(e.ClientNotFound, http.StatusBadRequest)
		} else {
			Log.Error("Error in GET client:" + err.Error())
			cx.RespondWithError(http.StatusBadRequest)
		}
		return
	}
	cx.RespondWithData(client)
}
开发者ID:jaredwilkening,项目名称:AWE,代码行数:28,代码来源:clientController.go

示例3: Delete

// DELETE: /job/{id}
func (cr *JobController) Delete(id string, cx *goweb.Context) {
	LogRequest(cx.Request)
	if err := queueMgr.DeleteJob(id); err != nil {
		cx.RespondWithErrorMessage("fail to delete job: "+id, http.StatusBadRequest)
		return
	}
	cx.RespondWithData("job deleted: " + id)
	return
}
开发者ID:eberroca,项目名称:AWE,代码行数:10,代码来源:jobController.go

示例4: ReadMany

// GET: /queue
// get status from queue manager
func (cr *QueueController) ReadMany(cx *goweb.Context) {
	LogRequest(cx.Request)

	// Gather query params
	//	query := &Query{list: cx.Request.URL.Query()}

	msg := queueMgr.ShowStatus()
	cx.RespondWithData(msg)
}
开发者ID:jaredwilkening,项目名称:AWE,代码行数:11,代码来源:queueController.go

示例5: ResourceDescription

func ResourceDescription(cx *goweb.Context) {
	LogRequest(cx.Request)
	r := resource{
		R: []string{"job", "work", "client", "queue"},
		U: apiUrl(cx) + "/",
		D: siteUrl(cx) + "/",
		C: conf.ADMIN_EMAIL,
		I: "AWE",
		T: "AWE",
	}
	cx.WriteResponse(r, 200)
}
开发者ID:jaredwilkening,项目名称:AWE,代码行数:12,代码来源:util.go

示例6: ResourceDescription

func ResourceDescription(cx *goweb.Context) {
	LogRequest(cx.Request)
	r := resource{
		R: []string{"node", "user"},
		U: apiUrl(cx) + "/",
		D: siteUrl(cx) + "/",
		C: conf.ADMIN_EMAIL,
		I: "Shock",
		T: "Shock",
	}
	cx.WriteResponse(r, 200)
}
开发者ID:eberroca,项目名称:Shock,代码行数:12,代码来源:util.go

示例7: DeleteMany

// DELETE: /job?suspend
func (cr *JobController) DeleteMany(cx *goweb.Context) {
	LogRequest(cx.Request)
	// Gather query params
	query := &Query{list: cx.Request.URL.Query()}

	if query.Has("suspend") {
		num := queueMgr.DeleteSuspendedJobs()
		cx.RespondWithData(fmt.Sprintf("deleted %d suspended jobs", num))
	} else {
		cx.RespondWithError(http.StatusNotImplemented)
	}
	return
}
开发者ID:eberroca,项目名称:AWE,代码行数:14,代码来源:jobController.go

示例8: handleAuthError

func handleAuthError(err error, cx *goweb.Context) {
	switch err.Error() {
	case e.MongoDocNotFound:
		cx.RespondWithErrorMessage("Invalid username or password", http.StatusBadRequest)
		return
		//	case e.InvalidAuth:
		//		cx.RespondWithErrorMessage("Invalid Authorization header", http.StatusBadRequest)
		//		return
	}
	Log.Error("Error at Auth: " + err.Error())
	cx.RespondWithError(http.StatusInternalServerError)
	return
}
开发者ID:eberroca,项目名称:AWE,代码行数:13,代码来源:jobController.go

示例9: PreAuthRequest

func PreAuthRequest(cx *goweb.Context) {
	LogRequest(cx.Request)
	id := cx.PathParams["id"]
	if p, err := store.LoadPreAuth(id); err != nil {
		if err.Error() == e.MongoDocNotFound {
			cx.RespondWithNotFound()
		} else {
			cx.RespondWithError(http.StatusInternalServerError)
			log.Error("err:@preAuth load: " + err.Error())
		}
		return
	} else {
		if node, err := store.LoadNodeUnauth(p.NodeId); err == nil {
			switch p.Type {
			case "download":
				filename := node.Id
				if fn, has := p.Options["filename"]; has {
					filename = fn
				}
				streamDownload(cx, node, filename)
				store.DeletePreAuth(id)
				return
			default:
				cx.RespondWithError(http.StatusInternalServerError)
			}
		} else {
			cx.RespondWithError(http.StatusInternalServerError)
			log.Error("err:@preAuth loadnode: " + err.Error())
		}
	}
	return
}
开发者ID:eberroca,项目名称:Shock,代码行数:32,代码来源:preAuthController.go

示例10: Update

// PUT: /work/{id} -> status update
func (cr *WorkController) Update(id string, cx *goweb.Context) {
	// Log Request and check for Auth
	LogRequest(cx.Request)
	// Gather query params
	query := &Query{list: cx.Request.URL.Query()}
	if query.Has("status") && query.Has("client") { //notify execution result: "done" or "fail"
		notice := core.Notice{WorkId: id, Status: query.Value("status"), ClientId: query.Value("client")}
		defer queueMgr.NotifyWorkStatus(notice)

		if query.Has("report") { // if "report" is specified in query, parse performance statistics
			_, files, err := ParseMultipartForm(cx.Request)
			if err != nil {
				Log.Error("[email protected]_Update_ParseMultipartForm: " + err.Error())
				cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
				return
			}
			if _, ok := files["perf"]; !ok {
				Log.Error("[email protected]_Update: no perf file uploaded")
				cx.RespondWithErrorMessage("no perf file uploaded", http.StatusBadRequest)
				return
			}
			if err := queueMgr.FinalizeWorkPerf(id, files["perf"].Path); err != nil {
				Log.Error("[email protected]_Update_FinalizeWorkPerf: " + err.Error())
				cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
				return
			}
		}
	}
	cx.RespondWithData("ok")
	return
}
开发者ID:eberroca,项目名称:AWE,代码行数:32,代码来源:workController.go

示例11: Read

// GET: /work/{id}
// get a workunit by id, read-only
func (cr *WorkController) Read(id string, cx *goweb.Context) {
	LogRequest(cx.Request)

	// Load workunit by id
	workunit, err := queueMgr.GetWorkById(id)

	if err != nil {
		if err.Error() != e.QueueEmpty {
			Log.Error("[email protected]_Read:QueueMgr.GetWorkById(): " + err.Error())
		}
		cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
		return
	}
	// Base case respond with workunit in json
	cx.RespondWithData(workunit)
	return
}
开发者ID:eberroca,项目名称:AWE,代码行数:19,代码来源:workController.go

示例12: ResourceDescription

func ResourceDescription(cx *goweb.Context) {
	LogRequest(cx.Request)
	host := ""
	if strings.Contains(cx.Request.Host, ":") {
		split := strings.Split(cx.Request.Host, ":")
		host = split[0]
	} else {
		host = cx.Request.Host
	}
	r := resource{
		R: []string{"job", "work", "client"},
		U: "http://" + host + ":" + fmt.Sprint(conf.API_PORT) + "/",
		D: "http://" + host + ":" + fmt.Sprint(conf.SITE_PORT) + "/",
		C: conf.ADMIN_EMAIL,
		I: "AWE",
		T: "AWE",
	}
	cx.WriteResponse(r, 200)
}
开发者ID:eberroca,项目名称:AWE,代码行数:19,代码来源:util.go

示例13: ReadMany

// GET: /client
func (cr *ClientController) ReadMany(cx *goweb.Context) {
	LogRequest(cx.Request)
	clients := queueMgr.GetAllClients()
	if len(clients) == 0 {
		cx.RespondWithErrorMessage(e.ClientNotFound, http.StatusBadRequest)
		return
	}

	query := &Query{list: cx.Request.URL.Query()}
	filtered := []*core.Client{}
	if query.Has("busy") {
		for _, client := range clients {
			if len(client.Current_work) > 0 {
				filtered = append(filtered, client)
			}
		}
	} else {
		filtered = clients
	}
	cx.RespondWithData(filtered)
}
开发者ID:jaredwilkening,项目名称:AWE,代码行数:22,代码来源:clientController.go

示例14: streamDownload

func streamDownload(cx *goweb.Context, node *store.Node, filename string) {
	query := &Query{list: cx.Request.URL.Query()}
	nf, err := node.FileReader()
	if err != nil {
		// File not found or some sort of file read error.
		// Probably deserves more checking
		log.Error("err:@preAuth node.FileReader: " + err.Error())
		cx.RespondWithError(http.StatusBadRequest)
		return
	}
	if query.Has("filename") {
		filename = query.Value("filename")
	}
	s := &streamer{rs: []store.SectionReader{nf}, ws: cx.ResponseWriter, contentType: "application/octet-stream", filename: filename, size: node.File.Size, filter: nil}
	err = s.stream()
	if err != nil {
		// causes "multiple response.WriteHeader calls" error but better than no response
		cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
		log.Error("err:@preAuth: s.stream: " + err.Error())
	}
}
开发者ID:eberroca,项目名称:Shock,代码行数:21,代码来源:preAuthController.go

示例15: Create

// POST: /client
func (cr *ClientController) Create(cx *goweb.Context) {
	// Log Request and check for Auth
	LogRequest(cx.Request)

	// Parse uploaded form
	_, files, err := ParseMultipartForm(cx.Request)
	if err != nil {
		if err.Error() != "request Content-Type isn't multipart/form-data" {
			Log.Error("Error parsing form: " + err.Error())
			cx.RespondWithError(http.StatusBadRequest)
			return
		}
	}

	client, err := queueMgr.RegisterNewClient(files)
	if err != nil {
		msg := "Error in registering new client:" + err.Error()
		Log.Error(msg)
		cx.RespondWithErrorMessage(msg, http.StatusBadRequest)
		return
	}

	//log event about client registration (CR)
	Log.Event(EVENT_CLIENT_REGISTRATION, "clientid="+client.Id+";name="+client.Name)

	cx.RespondWithData(client)
	return
}
开发者ID:jaredwilkening,项目名称:AWE,代码行数:29,代码来源:clientController.go


注:本文中的github.com/jaredwilkening/goweb.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。