本文整理汇总了Golang中github.com/InteractiveLecture/pgmapper.Mapper.Execute方法的典型用法代码示例。如果您正苦于以下问题:Golang Mapper.Execute方法的具体用法?Golang Mapper.Execute怎么用?Golang Mapper.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/InteractiveLecture/pgmapper.Mapper
的用法示例。
在下文中一共展示了Mapper.Execute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: upsertPermissionsHandler
func upsertPermissionsHandler(mapper *pgmapper.Mapper, objectIdExtractor idextractor.Extractor) http.Handler {
result := func(w http.ResponseWriter, r *http.Request) {
objectId, err := objectIdExtractor(r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
ids, ok := r.URL.Query()["sid"]
entity := make(map[string]interface{})
err = json.NewDecoder(r.Body).Decode(&entity)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
if ok {
err = mapper.Execute("SELECT insert_bulk_permissions(%v)", objectId, entity["create_permission"], entity["read_permission"], entity["update_permission"], entity["delete_permission"], ids)
} else {
_, err = mapper.ExecuteRaw("insert into acl_entries(object_id,sid,create_permission,read_permission,update_permission,delete_permission) values($1,$2,$3,$4,$5,$6) ON CONFLICT (object_id,sid) DO UPDATE SET create_permission = $3, read_permission = $4, update_permission = $5, delete_permission = $6 where acl_entries.sid = $2 AND acl_entries.object_id = $1", objectId, entity["sid"], entity["create_permission"], entity["read_permission"], entity["update_permission"], entity["delete_permission"])
}
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
}
return http.Handler(http.HandlerFunc(result))
}
示例2: TopicCreateHandler
func TopicCreateHandler(mapper *pgmapper.Mapper) http.Handler {
handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
var topic = make(map[string]interface{})
err := json.NewDecoder(r.Body).Decode(&topic)
if err != nil {
log.Println("error while decoding new topic json: ", err)
return http.StatusBadRequest
}
err = mapper.Execute("SELECT add_topic(%v)", topic["id"], topic["name"], topic["description"], topic["officers"])
if err != nil {
log.Println("error while inserting new topic into database")
return http.StatusBadRequest // TODO it could be an internal server error as well. need distinction
}
client := serviceclient.New("acl-service")
aclEntity, _ := json.Marshal(topic)
resp, err := client.Post("/objects", "application/json", bytes.NewReader(aclEntity), "Authorization", r.Header.Get("Authorization"))
if err != nil {
log.Println("error while creating acl-object: ", err)
return http.StatusInternalServerError
}
if resp.StatusCode >= 300 {
log.Println("got unexpected statuscode from acl-service while creating object: ", resp.StatusCode)
return http.StatusInternalServerError
}
return http.StatusCreated
}
return jwtware.New(createHandler(handlerFunc))
}
示例3: upsertMultiplePermissionsHandler
func upsertMultiplePermissionsHandler(mapper *pgmapper.Mapper, sidIdExtractor idextractor.Extractor) http.Handler {
result := func(w http.ResponseWriter, r *http.Request) {
sid, err := sidIdExtractor(r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
ids, ok := r.URL.Query()["oid"]
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
permissions := make(map[string]interface{})
err = json.NewDecoder(r.Body).Decode(&permissions)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
err = mapper.Execute("SELECT insert_bulk_sid_permissions(%v)", sid, permissions["create_permission"], permissions["read_permission"], permissions["update_permission"], permissions["delete_permission"], ids)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
return
}
return http.Handler(http.HandlerFunc(result))
}
示例4: deleteMultipleObjectsHandler
func deleteMultipleObjectsHandler(mapper *pgmapper.Mapper) http.Handler {
result := func(w http.ResponseWriter, r *http.Request) {
ids, ok := r.URL.Query()["oid"]
if !ok {
w.WriteHeader(http.StatusBadRequest)
}
err := mapper.Execute("SELECT delete_objects(%v)", ids)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
return http.Handler(http.HandlerFunc(result))
}
示例5: ExerciseStartHandler
func ExerciseStartHandler(mapper *pgmapper.Mapper, extractor idextractor.Extractor) http.Handler {
handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
user := context.Get(r, "user")
id := user.(*jwt.Token).Claims["id"]
exerciseId, err := extractor(r)
if err != nil {
return http.StatusInternalServerError
}
err = mapper.Execute("select start_exercise(%v)", exerciseId, id)
if err != nil {
return http.StatusNotFound
}
return -1
}
return jwtware.New(createHandler(handlerFunc))
}
示例6: TopicCreateHandler
func TopicCreateHandler(mapper *pgmapper.Mapper) http.Handler {
handlerFunc := func(w http.ResponseWriter, r *http.Request) int {
var topic = make(map[string]interface{})
err := json.NewDecoder(r.Body).Decode(topic)
if err != nil {
return http.StatusBadRequest
}
err = mapper.Execute("SELECT add_topic(%v)", topic["id"], topic["name"], topic["description"], topic["officers"])
if err != nil {
return http.StatusBadRequest // TODO it could be an internal server error as well. need distinction
}
w.WriteHeader(http.StatusCreated)
return -1
}
return createHandler(handlerFunc)
}
示例7: addObjectHandler
func addObjectHandler(mapper *pgmapper.Mapper) http.Handler {
result := func(w http.ResponseWriter, r *http.Request) {
entity := make(map[string]interface{})
err := json.NewDecoder(r.Body).Decode(&entity)
if err != nil {
log.Println("error while decoding json: ", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = mapper.Execute("insert into object_identities(id,parent_object) values(%v)", entity["id"], entity["parent"])
if err != nil {
log.Println("error while insertiing object into database: ", err)
w.WriteHeader(http.StatusBadRequest)
}
}
return http.Handler(http.HandlerFunc(result))
}
示例8: TopicRemoveOfficerHandler
func TopicRemoveOfficerHandler(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
}
var officer string
err = json.NewDecoder(r.Body).Decode(officer)
if err != nil {
return http.StatusBadRequest
}
err = mapper.Execute("SELECT remove_officer(%v)", id, officer)
if err != nil {
return http.StatusInternalServerError
}
return -1
}
return jwtware.New(createHandler(handlerFunc))
}
示例9: TopicAddOfficerHandler
func TopicAddOfficerHandler(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
}
var officer string
err = json.NewDecoder(r.Body).Decode(officer)
if err != nil {
return http.StatusBadRequest
}
err = mapper.Execute(`SELECT add_officer($1,$2)`, id, officer)
if err != nil {
return http.StatusInternalServerError
}
return -1
}
return createHandler(handlerFunc)
}
示例10: ExerciseStartHandler
func ExerciseStartHandler(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
}
var exerciseId string
err = json.NewDecoder(r.Body).Decode(exerciseId)
if err != nil {
return http.StatusBadRequest
}
err = mapper.Execute("insert into exercise_progress_histories(user_id,exercise_id,amount,time,state) values(%v)", id, exerciseId, 0, time.Now(), 1)
if err != nil {
return http.StatusNotFound
}
return -1
}
return createHandler(handlerFunc)
}