本文整理汇总了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))
}
示例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)
}
示例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))
}
示例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))
}
示例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))
}
示例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)
}
示例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)
}
示例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))
}
示例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))
}
示例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)
}