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


Golang Mapper.PreparedQueryIntoBytes方法代码示例

本文整理汇总了Golang中github.com/InteractiveLecture/pgmapper.Mapper.PreparedQueryIntoBytes方法的典型用法代码示例。如果您正苦于以下问题:Golang Mapper.PreparedQueryIntoBytes方法的具体用法?Golang Mapper.PreparedQueryIntoBytes怎么用?Golang Mapper.PreparedQueryIntoBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/InteractiveLecture/pgmapper.Mapper的用法示例。


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

示例1: ModulesTreeHandler

func ModulesTreeHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		id, err := extractor(r)
		if err != nil {
			log.Println("error with extractor in ModulesTreeHandler")
			return http.StatusBadRequest
		}
		dr, err := paginator.ParseDepth(r.URL)
		if err != nil {
			log.Println("error parsing depth request in ModulesTreeHandler")
			return http.StatusInternalServerError
		}
		result, err := mapper.PreparedQueryIntoBytes("SELECT get_module_tree(%v)", id, dr.Descendants, dr.Ancestors)
		if err != nil {
			log.Println(err)
			return http.StatusInternalServerError
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return jwtware.New(createHandler(handlerFunc))
}
开发者ID:InteractiveLecture,项目名称:lecture-service,代码行数:26,代码来源:moduleshandler.go

示例2: HintHistoryHandler

func HintHistoryHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		pr, err := paginator.ParsePages(r.URL)
		if err != nil {
			return http.StatusInternalServerError
		}
		id, err := extractor(r)
		if err != nil {
			return http.StatusInternalServerError
		}
		var result []byte
		ids, ok := r.URL.Query()["exercise_id"]
		if ok {
			result, err = mapper.PreparedQueryIntoBytes("SELECT get_hint_purchase_history(%v)", id, pr.Size, pr.Size*pr.Number, ids[0])
		} else {
			result, err = mapper.PreparedQueryIntoBytes("SELECT get_hint_purchase_history(%v)", id, pr.Size, pr.Size*pr.Number)
		}
		if err != nil {
			log.Println(err)
			return http.StatusNotFound
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return createHandler(handlerFunc)
}
开发者ID:Richterrettich,项目名称:lecture-service,代码行数:30,代码来源:historyhandler.go

示例3: PurchaseHintHandler

func PurchaseHintHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		id, err := extractor(r)
		if err != nil {
			return http.StatusBadRequest
		}
		userId := context.Get(r, "user").(*jwt.Token).Claims["id"].(string)
		result, err := mapper.PreparedQueryIntoBytes("SELECT purchase_hint(%v)", id, userId)
		if err != nil {
			log.Println(err)
			return http.StatusInternalServerError
		}
		purchaseResult, _ := strconv.Atoi(string(result))
		log.Println("hint purchase achieved the following result: ", purchaseResult)
		switch {
		case purchaseResult == 0:
			//hint purchase without errors
			return -1
		case purchaseResult == 1:
			//balance not sufficient
			return 420
		case purchaseResult == 2:
			//already purchased
			return http.StatusConflict
		case purchaseResult == 3:
			//hint not found
			return http.StatusNotFound
		default:
			//something different went wrong
			return http.StatusInternalServerError
		}
	}
	return jwtware.New(createHandler(handlerFunc))
}
开发者ID:InteractiveLecture,项目名称:lecture-service,代码行数:34,代码来源:exercisehandler.go

示例4: ExerciseHistoryHandler

func ExerciseHistoryHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		pr, err := paginator.ParsePages(r.URL)
		if err != nil {
			return http.StatusInternalServerError
		}
		id, err := extractor(r)
		if err != nil {
			return http.StatusInternalServerError
		}
		limit := pr.Size
		skip := pr.Size * pr.Number
		if pr.Number == -1 || pr.Size == -1 {
			skip = -1
		}
		var result []byte
		if ids, ok := r.URL.Query()["module_id"]; ok {
			result, err = mapper.PreparedQueryIntoBytes("SELECT get_exercise_history(%v)", id, limit, skip, ids[0])
		} else {
			result, err = mapper.PreparedQueryIntoBytes("SELECT get_exercise_history(%v)", id, limit, skip)
		}
		if err != nil {
			return http.StatusNotFound
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return jwtware.New(createHandler(handlerFunc))
}
开发者ID:InteractiveLecture,项目名称:lecture-service,代码行数:33,代码来源:historyhandler.go

示例5: TopicBalanceHandler

func TopicBalanceHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		id, err := extractor(r)
		if err != nil {
			return http.StatusInternalServerError
		}
		result, err := mapper.PreparedQueryIntoBytes("Select get_balances(%v)", id)
		if err != nil {
			return http.StatusNotFound
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return jwtware.New(createHandler(handlerFunc))
}
开发者ID:InteractiveLecture,项目名称:lecture-service,代码行数:19,代码来源:historyhandler.go

示例6: TopicFindHandler

func TopicFindHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		id, err := extractor(r)
		if err != nil {
			return http.StatusInternalServerError
		}
		result, err := mapper.PreparedQueryIntoBytes(`SELECT get_topic($1)`, id)
		if err != nil {
			return http.StatusNotFound
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return createHandler(handlerFunc)
}
开发者ID:Richterrettich,项目名称:lecture-service,代码行数:19,代码来源:topicshandler.go

示例7: NextModulesForUserHandler

func NextModulesForUserHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		id, err := extractor(r)
		if err != nil {
			return http.StatusInternalServerError
		}
		result, err := mapper.PreparedQueryIntoBytes("SELECT get_next_modules_for_user(%v)", id)
		if err != nil {
			return http.StatusNotFound
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return createHandler(handlerFunc)
}
开发者ID:Richterrettich,项目名称:lecture-service,代码行数:19,代码来源:historyhandler.go

示例8: TopicCollectionHandler

func TopicCollectionHandler(mapper *pgmapper.Mapper) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		pageRequest, err := paginator.ParsePages(r.URL)
		if err != nil {
			return http.StatusInternalServerError
		}
		result, err := mapper.PreparedQueryIntoBytes("SELECT * from query_topics(%v)", pageRequest.Number*pageRequest.Size, pageRequest.Size)
		if err != nil {
			log.Println(err)
			return http.StatusInternalServerError
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return jwtware.New(createHandler(handlerFunc))
}
开发者ID:InteractiveLecture,项目名称:lecture-service,代码行数:20,代码来源:topicshandler.go

示例9: GetHintHandler

func GetHintHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		id, err := extractor(r)
		if err != nil {
			return http.StatusBadRequest
		}
		userId := context.Get(r, "user").(*jwt.Token).Claims["id"].(string)
		result, err := mapper.PreparedQueryIntoBytes("SELECT get_hint(%v)", userId, id)
		switch {
		case err != nil:
			return http.StatusInternalServerError
		case len(result) == 0:
			return http.StatusPaymentRequired
		}
		reader := bytes.NewReader(result)
		_, err = io.Copy(w, reader)
		if err != nil {
			log.Println(err)
		}
		return -1
	}
	return jwtware.New(createHandler(handlerFunc))
}
开发者ID:InteractiveLecture,项目名称:lecture-service,代码行数:23,代码来源:exercisehandler.go

示例10: PurchaseHintHandler

func PurchaseHintHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
	handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
		id, err := extractor(r)
		if err != nil {
			return http.StatusBadRequest
		}
		userId := context.Get(r, "user").(*jwt.Token).Claims["id"].(string)
		result, err := mapper.PreparedQueryIntoBytes("SELECT purchase_hint(%v)", id, userId)
		purchaseResult, _ := binary.Varint(result) //TODO check function...something is fishy
		switch {
		case purchaseResult == 0:
			return -1
		case purchaseResult == 1:
			return 420
		case purchaseResult == 2:
			return http.StatusConflict
		case purchaseResult == 3:
			return http.StatusNotFound
		default:
			return http.StatusInternalServerError
		}
	}
	return createHandler(handlerFunc)
}
开发者ID:Richterrettich,项目名称:lecture-service,代码行数:24,代码来源:exercisehandler.go


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