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


Golang encoder.Encoder类代码示例

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


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

示例1: CreateGoal

func CreateGoal(enc encoder.Encoder, goal Goal) (int, []byte) {
	goalId, err := uuid.NewV4()
	if err != nil {
		return 500, encoder.Must(enc.Encode(""))
	}
	goal.Id = goalId.String()
	if goal.TargetType == "user" {
		user, ok := users[goal.Target]
		if !ok {
			return 400, encoder.Must(enc.Encode("Target does not exist"))
		}
		user.Goals[goal.Id] = &goal
	} else if goal.TargetType == "team" {
		team, ok := teams[goal.Target]
		if !ok {
			return 400, encoder.Must(enc.Encode("Target does not exist"))
		}
		team.Goals[goal.Id] = &goal
	} else {
		return 400, encoder.Must(enc.Encode("Unknown target type"))
	}

	goals[goal.Id] = &goal
	return 201, encoder.Must(enc.Encode(goal.Id))
}
开发者ID:FP7Collage,项目名称:GoalSetting,代码行数:25,代码来源:goals.go

示例2: GetGoal

func GetGoal(enc encoder.Encoder, params martini.Params) (int, []byte) {
	goal, ok := goals[params["id"]]
	if ok {
		return 200, encoder.Must(enc.Encode(goal))
	}
	return 404, encoder.Must(enc.Encode())
}
开发者ID:FP7Collage,项目名称:GoalSetting,代码行数:7,代码来源:goals.go

示例3: GetUsers

func GetUsers(dataStore DataStore, enc encoder.Encoder) (int, []byte) {
	users, err := dataStore.GetAllUsers()
	if err != nil {
		return http.StatusNoContent, encoder.Must(enc.Encode(NewError(ErrInternal, "Can't get users try again later")))
	}
	return http.StatusOK, encoder.Must(enc.Encode(users))
}
开发者ID:Blagomir,项目名称:WhoIsInTheLab,代码行数:7,代码来源:registration.go

示例4: FetchStatus

func FetchStatus(s *Status, ms *mgo.Session, enc encoder.Encoder, r *http.Request) (int, []byte) {
	s.Log["MongoDB"] = NewLog(true, "")
	if err := ms.Ping(); err != nil {
		s.Log["MongoDB"] = NewLog(false, err.Error())
	}
	return http.StatusOK, encoder.Must(enc.Encode(s))
}
开发者ID:ranveerkunal,项目名称:admin,代码行数:7,代码来源:admin.go

示例5: GetMac

func GetMac(res http.ResponseWriter, req *http.Request, enc encoder.Encoder) (int, []byte) {
	ip := strings.Split(req.RemoteAddr, ":")[0]
	mac, err := GetMacAddress("/proc/net/arp", ip)
	if err != nil {
		return http.StatusNotFound, encoder.Must(enc.Encode(NewError(ErrMacNotFound, err.Error())))
	}
	return http.StatusOK, encoder.Must(enc.Encode(map[string]string{"mac": mac}))
}
开发者ID:Blagomir,项目名称:WhoIsInTheLab,代码行数:8,代码来源:registration.go

示例6: listLocations

func listLocations(enc encoder.Encoder, r *http.Request, db *mgo.Database) (int, []byte) {
	var locations []Location

	c := db.C("locations")
	err := c.Find(nil).All(&locations)
	if err != nil {
		return http.StatusInternalServerError, []byte("Impossible to retrieve the locations: " + err.Error())
	}

	return http.StatusOK, encoder.Must(enc.Encode(locations))
}
开发者ID:K-Phoen,项目名称:BeThere,代码行数:11,代码来源:locations_api.go

示例7: GetServer

func GetServer(enc encoder.Encoder, db database.DB, parms martini.Params) (int, []byte) {
	fmt.Printf("begin get server\n")
	id, err := strconv.ParseInt(parms["id"], 10, 64)
	al := db.Get(id)
	if err != nil || al == nil {
		msg := fmt.Sprintf("the album with id %s does not exist", parms["id"])
		return http.StatusNotFound, encoder.Must(enc.Encode(
			NewError{errcode: 404, errmsg: msg}))
	}
	return http.StatusOK, encoder.Must(enc.Encode(al))
}
开发者ID:yc850k,项目名称:haha,代码行数:11,代码来源:server.go

示例8: FindServer

func FindServer(enc encoder.Encoder, db database.DB, r *http.Request) (int, []byte) {
	fmt.Printf("begin find server\n")
	params := r.URL.Query()
	roomId, err := strconv.ParseInt(params.Get("room_id"), 10, 64)
	al := db.Find(roomId)
	if err != nil || al == nil {
		msg := fmt.Sprintf("server witch room_id %s does not exist", params.Get("id"))
		return http.StatusNotFound, encoder.Must(enc.Encode(
			NewError{errcode: 404, errmsg: msg}))
	}
	return http.StatusOK, encoder.Must(enc.Encode(al))
}
开发者ID:yc850k,项目名称:haha,代码行数:12,代码来源:server.go

示例9: getLocation

func getLocation(params martini.Params, enc encoder.Encoder, db *mgo.Database) (int, []byte) {
	var location Location

	if !bson.IsObjectIdHex(params["id"]) {
		return http.StatusNotFound, []byte("Location with id \"" + params["id"] + "\" not found")
	}

	c := db.C("locations")
	err := c.FindId(bson.ObjectIdHex(params["id"])).One(&location)
	if err != nil {
		return http.StatusNotFound, []byte("Location with id \"" + params["id"] + "\" not found")
	}

	return http.StatusOK, encoder.Must(enc.Encode(location))
}
开发者ID:K-Phoen,项目名称:BeThere,代码行数:15,代码来源:locations_api.go

示例10: CompleteGoal

func CompleteGoal(enc encoder.Encoder, params martini.Params, jsonParams GoalCompleteParams) (int, []byte) {
	goal, ok := goals[params["id"]]
	if !ok {
		return 404, encoder.Must(enc.Encode())
	}
	if _, ok := users[jsonParams.UserId]; !ok {
		return 400, encoder.Must(enc.Encode("User does not exist"))
	}
	goal.NumberOfCompletions--
	if goal.NumberOfCompletions > 0 {
		goal.State = "progress"
		return 200, encoder.Must(enc.Encode(goal.State)) //what should be returned here?
	}

	goal.State = "completed"
	return 200, encoder.Must(enc.Encode(goal.Reward))
}
开发者ID:FP7Collage,项目名称:GoalSetting,代码行数:17,代码来源:goals.go

示例11: createLocation

func createLocation(newLocation NewLocationForm, enc encoder.Encoder, db *mgo.Database) (int, []byte) {
	// transform the form struct into a real Location
	location := Location{
		ID: bson.NewObjectId(),
		Coordinates: Coordinates{
			Lat:  newLocation.Lat,
			Long: newLocation.Long,
		},
		Name:        newLocation.Name,
		Description: newLocation.Description,
		Visited:     newLocation.Visited,
		CreatedAt:   time.Now(),
	}

	// and try to insert it
	c := db.C("locations")
	err := c.Insert(&location)

	if err != nil {
		return http.StatusInternalServerError, []byte("Impossible to insert the location: " + err.Error())
	}

	return http.StatusCreated, encoder.Must(enc.Encode(location))
}
开发者ID:K-Phoen,项目名称:BeThere,代码行数:24,代码来源:locations_api.go

示例12: GetUser

func GetUser(dataStore DataStore, enc encoder.Encoder, params martini.Params) (int, []byte) {
	id, err := strconv.Atoi(params["id"])
	if err != nil {
		return http.StatusNotFound, encoder.Must(enc.Encode(NewError(ErrInternal, "Invalid id")))
	}

	user, dbErr := dataStore.GetUser(id)
	if dbErr != nil {
		return http.StatusNotFound, encoder.Must(enc.Encode(NewError(ErrUserNotFound, dbErr.Error())))
	}
	return http.StatusOK, encoder.Must(enc.Encode(user))
}
开发者ID:Blagomir,项目名称:WhoIsInTheLab,代码行数:12,代码来源:registration.go

示例13: CreatePreset

func CreatePreset(
	params martini.Params, w http.ResponseWriter,
	r *http.Request, enc encoder.Encoder) (int, []byte) {
	bytes, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return http.StatusBadRequest,
			encoder.Must(enc.Encode(&Error{err.Error()}))
	}
	preset := &Preset{}
	err = json.Unmarshal(bytes, &preset)
	if err != nil {
		return http.StatusBadRequest,
			encoder.Must(enc.Encode(&Error{err.Error()}))
	}
	presets.Add(preset)
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	return http.StatusCreated, encoder.Must(enc.Encode(preset))
}
开发者ID:kevinjqiu,项目名称:imposter,代码行数:18,代码来源:imposter.go

示例14: GetTeams

func GetTeams(enc encoder.Encoder) (int, []byte) {
	return 200, encoder.Must(enc.Encode(teams))
}
开发者ID:FP7Collage,项目名称:GoalSetting,代码行数:3,代码来源:users.go

示例15: GetUsers

func GetUsers(enc encoder.Encoder) (int, []byte) {
	return 200, encoder.Must(enc.Encode(users))
}
开发者ID:FP7Collage,项目名称:GoalSetting,代码行数:3,代码来源:users.go


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