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


Golang router.Request类代码示例

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


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

示例1: registerUser

func registerUser(request router.Request) (int, []byte) {
	var registration UserResgistration
	err := json.Unmarshal(request.GetContent(), &registration)

	//Check for correct desrialization
	if err != nil {
		log.Errorf(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	//check if username already exists
	if IsUsernameAvailable(registration.UserName, request.GetContext()) {

		// generate a random salt with default rounds of complexity
		salt, _ := bcrypt.Salt()

		// hash and verify a password with random salt
		hash, _ := bcrypt.Hash(registration.Password)

		var user = UserData{registration.UserName, nil, salt, hash}
		err = SaveUserToGAE(user, request.GetContext())
		if err != nil {
			log.Errorf(request.GetContext(), "error: %v", err)
			return http.StatusInternalServerError, []byte(err.Error())
		} else {
			return http.StatusOK, nil
		}
	} else {
		return http.StatusConflict, []byte("Username not avaiable")
	}
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:31,代码来源:user_resource.go

示例2: checkProject

//TODO: Check if project is enabled
func checkProject(request router.Request) (int, []byte) {

	//Get The project
	projectId := request.GetPathParams()["project_id"]
	projectObj, getProjectStatus, getProjectError := getProject(projectId, request.GetContext())
	//Get Alerts
	alerts, getAlertStatus, getAlertsError := getAlerts(projectId, request.GetContext())
	//Get Subscriptions
	subscriptions, getSubsStatus, getSubsError := getSubscriptions(projectId, request.GetContext())

	if getProjectError == nil && getAlertsError == nil && getSubsError == nil {
		//Check Alerts
		return processAlerts(projectObj, alerts, subscriptions, request.GetContext())
	} else {
		return processError(getProjectStatus, getAlertStatus, getSubsStatus,
			getProjectError, getAlertsError, getSubsError)
	}

}
开发者ID:usmanismail,项目名称:klaxon,代码行数:20,代码来源:check_resource.go

示例3: postSubscription

//Create/Update an subscription for the given project
func postSubscription(request router.Request) (int, []byte) {

	var subscription Subscription
	err := json.Unmarshal(request.GetContent(), &subscription)
	if err != nil {
		log.Errorf(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	subscription.Project = request.GetPathParams()["project_id"]
	err = SaveSubscriptionToGAE(subscription, request.GetContext())

	if err != nil {
		log.Errorf(request.GetContext(), "error: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	return http.StatusOK, nil

}
开发者ID:usmanismail,项目名称:klaxon,代码行数:21,代码来源:subscription_resource.go

示例4: postAlert

//Create/Update an alert for the given project
func postAlert(request router.Request) (int, []byte) {

	var alert Alert
	err := json.Unmarshal(request.GetContent(), &alert)
	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	//TODO Check Project Exists
	alert.Project = request.GetPathParams()["project_id"]
	err = SaveAlertToGAE(alert, request.GetContext())
	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	return http.StatusOK, nil

}
开发者ID:usmanismail,项目名称:klaxon,代码行数:21,代码来源:alert_resource.go

示例5: getAlert

//Get a specific alert for a project
func getAlert(request router.Request) (int, []byte) {

	alert, err := GetAlertFromGAE(request.GetPathParams()["project_id"], request.GetPathParams()["alert_id"], request.GetContext())

	if err != nil && strings.Contains(err.Error(), "no such entity") {
		log.Errorf(request.GetContext(), "Error retriving Alert: %v", err)
		return http.StatusNotFound, []byte("Alert not found")
	} else if err != nil {
		log.Errorf(request.GetContext(), "Error retriving alert: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	} else {
		var alertJSON, err = json.MarshalIndent(alert, "", "	")
		if err == nil {
			return http.StatusOK, alertJSON
		} else {
			log.Errorf(request.GetContext(), "Errror %v", err)
			return http.StatusBadRequest, []byte(err.Error())
		}
	}
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:21,代码来源:alert_resource.go

示例6: getAlerts

//Get all alerts for a given project
func getAlerts(request router.Request) (int, []byte) {
	alerts, err := GetAlertsFromGAE(request.GetPathParams()["project_id"], request.GetContext())
	if err != nil {
		log.Errorf(request.GetContext(), "Error retriving alerts: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	} else {
		alertBytes, err := json.MarshalIndent(alerts, "", "	")
		if err != nil {
			log.Errorf(request.GetContext(), "Error retriving Alerts: %v", err)
			return http.StatusInternalServerError, []byte(err.Error())
		}
		return http.StatusOK, alertBytes
	}
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:15,代码来源:alert_resource.go

示例7: getAllProjects

//Get all projects
//TODO: Check for Admin to return all
//TODO: If not admin only return current users projects
func getAllProjects(request router.Request) (int, []byte) {

	projectDTOs, err := GetProjectDTOsFromGAE(request.GetContext())

	if err != nil {
		log.Errorf(request.GetContext(), "Errorf retriving project: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	} else {
		//Convert to Projects
		var projects []Project
		for _, projectDTO := range projectDTOs {
			var project, err = projectDTO.GetProject()
			if err == nil {
				projects = append(projects, project)
			} else {
				return http.StatusInternalServerError, []byte(err.Error())
			}
		}

		projectBytes, err := json.MarshalIndent(projects, "", "	")
		if err != nil {
			log.Errorf(request.GetContext(), "Errorf retriving Projects: %v", err)
			return http.StatusInternalServerError, []byte(err.Error())
		}
		return http.StatusOK, projectBytes
	}
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:30,代码来源:project_resource.go

示例8: getSubscription

//Get a specific subscription for a project
func getSubscription(request router.Request) (int, []byte) {

	subscription, err := GetSubscriptionFromGAE(request.GetPathParams()["project_id"], request.GetPathParams()["subscription_id"], request.GetContext())

	if err != nil && strings.Contains(err.Error(), "no such entity") {
		return http.StatusNotFound, []byte("Subscription not found")
	} else if err != nil {
		log.Errorf(request.GetContext(), "Error retriving Subsciption: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	} else {
		subscriptionBytes, err := json.MarshalIndent(subscription, "", "	")
		if err == nil {
			return http.StatusOK, subscriptionBytes
		} else {
			log.Errorf(request.GetContext(), "Errror %v", err)
			return http.StatusInternalServerError, []byte(err.Error())
		}

	}
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:21,代码来源:subscription_resource.go

示例9: getTick

func getTick(request router.Request) (int, []byte) {

	query := datastore.NewQuery(project.PROJECT_KEY)
	projects := make([]project.ProjectDTO, 0)
	_, err := query.GetAll(request.GetContext(), &projects)

	if err != nil {
		log.Errorf(request.GetContext(), "Error retriving projects: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	} else {

		for _, project := range projects {
			task := taskqueue.NewPOSTTask("/rest/internal/check/"+project.Name, nil)
			if _, err := taskqueue.Add(request.GetContext(), task, "alertCheckQueue"); err != nil {
				log.Errorf(request.GetContext(), "Error posting to task queue: %v", err)
			}

		}

		return http.StatusOK, nil
	}
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:22,代码来源:tick_resource.go

示例10: getUsers

func getUsers(request router.Request) (int, []byte) {
	users, err := GetUsersFromGAE(request.GetContext())

	if err != nil {
		log.Errorf(request.GetContext(), "Error retriving user: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	} else {
		userBytes, err := json.MarshalIndent(users, "", "	")
		if err == nil {
			return http.StatusOK, userBytes
		} else {
			log.Errorf(request.GetContext(), "Errror %v", err)
			return http.StatusInternalServerError, []byte(err.Error())
		}
	}
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:16,代码来源:user_resource.go

示例11: updateProject

//Create/Update a project
//TODO: Check Admin/User Permissions
//TODO: Check required config present
//TODO: If create add to user project list
func updateProject(request router.Request) (int, []byte) {

	var project ProjectStruct
	err := json.Unmarshal(request.GetContent(), &project)
	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusBadRequest, []byte(err.Error())
	}

	projectDTO, err := project.GetDTO()
	if err != nil {
		return http.StatusInternalServerError, []byte(err.Error())

	}
	err = SaveProjectDTOToGAE(projectDTO, request.GetContext())

	if err != nil {
		log.Infof(request.GetContext(), "error: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	return http.StatusOK, nil
}
开发者ID:usmanismail,项目名称:klaxon,代码行数:27,代码来源:project_resource.go

示例12: getSubscriptions

//Get all subscriptions for a given project
func getSubscriptions(request router.Request) (int, []byte) {

	subscriptions, err := GetSubscriptionsFromGAE(request.GetPathParams()["project_id"], request.GetContext())

	if err != nil {
		log.Errorf(request.GetContext(), "Error retriving Subscriptions: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	subscriptionBytes, err := json.MarshalIndent(subscriptions, "", "	")

	if err != nil {
		log.Errorf(request.GetContext(), "Error retriving Subscriptions: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	}

	return http.StatusOK, subscriptionBytes

}
开发者ID:usmanismail,项目名称:klaxon,代码行数:20,代码来源:subscription_resource.go

示例13: getProject

//Get a specific project
func getProject(request router.Request) (int, []byte) {

	projectDTO, err := GetProjectDTOFromGAE(request.GetPathParams()["project_id"], request.GetContext())

	if err != nil && strings.Contains(err.Error(), "no such entity") {
		log.Errorf(request.GetContext(), "Error retriving Project: %v", err)
		return http.StatusNotFound, []byte("Project Not Found")
	} else if err != nil {
		log.Errorf(request.GetContext(), "Error retriving project: %v", err)
		return http.StatusInternalServerError, []byte(err.Error())
	} else {
		project, err := projectDTO.GetProject()
		if err != nil {
			log.Infof(request.GetContext(), "Error %v", err)
			return http.StatusInternalServerError, []byte(err.Error())

		}

		projectJSON, err := json.MarshalIndent(project, "", "	")
		if err != nil {
			log.Infof(request.GetContext(), "Error %v", err)
			return http.StatusInternalServerError, []byte(err.Error())

		}

		return http.StatusOK, projectJSON

	}

}
开发者ID:usmanismail,项目名称:klaxon,代码行数:31,代码来源:project_resource.go


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