本文整理汇总了Golang中github.com/ant0ine/go-json-rest/rest.Request.PathParam方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.PathParam方法的具体用法?Golang Request.PathParam怎么用?Golang Request.PathParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ant0ine/go-json-rest/rest.Request
的用法示例。
在下文中一共展示了Request.PathParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PostMsg
func (mqmsg MqMsg) PostMsg(w rest.ResponseWriter, r *rest.Request) {
//msg := message.NewMsg()
mqid, err := strconv.Atoi(r.PathParam("mqid"))
if err != nil {
log.Log("info", err.Error(), nil)
}
mq, ok := DefaultMM[mqid]
if ok {
mqmsg.Msg.MQid = mqid
mqmsg.Msg.Generator = mq.Owner
mqmsg.Msg.MsgId = Counter
Counter++
r.DecodeJsonPayload(mqmsg.Msg)
fmt.Println(mqmsg.Msg.Value)
//fmt.Println("post msg")
mq.Lock()
mq.AddMsg(*mqmsg.Msg)
mq.Unlock()
//w.WriteJson(mqmsg.Msg)
w.WriteJson(map[string]string{"1016": "post success"})
} else {
w.WriteJson(map[string]string{"1010": "mq not running"})
}
}
示例2: GetCluster
// GetCluster returns a given cluster definition
func GetCluster(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
results, err := admindb.GetCluster(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
}
cluster := types.Cluster{}
cluster.ID = results.ID
cluster.ProjectID = results.ProjectID
cluster.Name = results.Name
cluster.ClusterType = results.ClusterType
cluster.Status = results.Status
cluster.CreateDate = results.CreateDate
cluster.Containers = results.Containers
//logit.Info.Println("GetCluser:db call results=" + results.ID)
w.WriteJson(&cluster)
}
示例3: GetUser
func (api *Api) GetUser(w rest.ResponseWriter, r *rest.Request) {
id := r.PathParam("id")
user := &User{}
rows, err := api.DB.Query("SELECT * FROM " + TABLENAME + " WHERE ID = " + id)
if err != nil {
log.Fatal(err)
}
if rows.Next() {
var id int
var name string
if err := rows.Scan(&id, &name); err != nil {
log.Fatal(err)
}
user = &User{Id: id, Name: name}
} else {
rest.NotFound(w, r)
return
}
if err := rows.Err(); err != nil {
log.Fatal(err)
}
w.WriteJson(&user)
}
示例4: HandleCreateEvent
// Require a write key.
// Create a event.
func HandleCreateEvent(w rest.ResponseWriter, req *rest.Request) {
if err := RequireWriteKey(w, req); err != nil {
rest.Error(w, err.Error(), err.(StatusError).Code)
return
}
project := currentProject(req)
event := req.PathParam("event_name")
var data CreateSingleEventParams
var err error
if err = eventData(req, &data); err != nil {
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
events := make(map[string][]interface{})
events[event] = []interface{}{data}
result, err := createEvent(project, event, data)
if err != nil {
rest.Error(w, err.Error(), http.StatusBadRequest)
} else {
w.WriteJson(result)
}
}
示例5: renewInstance
func (routes *Routes) renewInstance(w rest.ResponseWriter, r *rest.Request) {
iid := r.PathParam(RouteParamInstanceID)
if iid == "" {
routes.logger.WithFields(log.Fields{
"namespace": r.Env["REMOTE_USER"],
"error": "instance id is required",
}).Warn("Failed to renew instance")
i18n.Error(r, w, http.StatusBadRequest, i18n.ErrorInstanceIdentifierMissing)
return
}
catalog := routes.catalog(w, r)
if catalog == nil {
routes.logger.WithFields(log.Fields{
"namespace": r.Env["REMOTE_USER"],
"error": "catalog is nil",
}).Errorf("Failed to renew instance %s", iid)
return
}
if err := catalog.Renew(iid); err != nil {
routes.logger.WithFields(log.Fields{
"namespace": r.Env["REMOTE_USER"],
"error": err,
}).Warnf("Failed to renew instance %s", iid)
i18n.Error(r, w, statusCodeFromError(err), i18n.ErrorInstanceHeartbeatFailed)
return
}
w.WriteHeader(http.StatusOK)
}
示例6: GetHealthCheck
func GetHealthCheck(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection("clusteradmin")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println("validate token error " + err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
var results []collect.HealthCheck
results, err = collect.GetHealthCheck(dbConn)
if err != nil {
logit.Error.Println(err.Error())
w.WriteJson(&results)
return
}
w.WriteJson(&results)
}
示例7: AuthenticationAPI
func AuthenticationAPI(w rest.ResponseWriter, req *rest.Request) {
fmt.Println(":: AuthenticationAPI ::")
ip, _ := net.LookupIP(req.PathParam("host"))
// rest.Error(w, err.Error(), http.StatusInternalServerError)
w.WriteJson(&ip)
w.WriteJson(map[string]interface{}{"Body": ip})
}
示例8: DeletePost
func (api *Api) DeletePost(w rest.ResponseWriter, r *rest.Request) {
_, err := api.validateAuthHeader(r.Request)
if err != nil {
rest.Error(w, "Authorization invalid", http.StatusUnauthorized)
return
}
_id := r.PathParam("id")
id, err := strconv.ParseInt(_id, 10, 64)
post := db.Post{}
if err = api.First(&post, id).Error; err != nil {
if err == gorm.RecordNotFound {
rest.NotFound(w, r)
return
} else {
log.Println(gormLoadError("post"), err)
rest.Error(w, INTERNALERROR, http.StatusInternalServerError)
return
}
}
if err := api.Delete(&post).Error; err != nil {
log.Println(gormDeleteError("post"), err)
rest.Error(w, INTERNALERROR, http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
示例9: DeleteCountry
func DeleteCountry(w rest.ResponseWriter, r *rest.Request) {
code := r.PathParam("code")
lock.Lock()
delete(store, code)
lock.Unlock()
w.WriteHeader(http.StatusOK)
}
示例10: GetEntry
func (api *Api) GetEntry(w rest.ResponseWriter, r *rest.Request) {
idParam := r.PathParam("id")
entries := &PlaylistEntry{}
rows, err := api.DB.Query("SELECT ROWID, " + COLNAME1 + ", " + COLNAME2 + " FROM " + TABLENAME + " WHERE ROWID = " + idParam)
if err != nil {
log.Fatal(err)
}
if rows.Next() {
var id int
var url string
var played int
if err := rows.Scan(&id, &url, &played); err != nil {
log.Fatal(err)
}
entries = &PlaylistEntry{Id: id, Url: url, Played: played}
} else {
rest.NotFound(w, r)
return
}
if err := rows.Err(); err != nil {
log.Fatal(err)
}
w.WriteJson(&entries)
}
示例11: GetProject
func GetProject(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println("BackupNow: error " + err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println("GetProject: validate token error " + err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
logit.Error.Println("GetProject: error Project ID required")
rest.Error(w, "Project ID required", http.StatusBadRequest)
return
}
results, err := admindb.GetProject(dbConn, ID)
if err != nil {
logit.Error.Println("GetProject:" + err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
project := Project{results.ID, results.Name, results.Desc, results.UpdateDate, "", results.Containers, results.Clusters}
w.WriteJson(&project)
}
示例12: DeleteUser
func (u *Users) DeleteUser(w rest.ResponseWriter, r *rest.Request) {
id := r.PathParam("id")
u.Lock()
delete(u.Store, id)
u.Unlock()
w.WriteHeader(http.StatusOK)
}
示例13: GetStatus
func GetStatus(w rest.ResponseWriter, r *rest.Request) {
Token := r.PathParam("Token")
if Token == "" {
rest.Error(w, "Token required", 400)
return
}
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println("BackupNow: error " + err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, Token, "perm-read")
if err != nil {
logit.Error.Println("GetStatus: validate token error " + err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
rest.Error(w, "ID required", 400)
return
}
stat, err := backup.GetStatus(dbConn, ID)
if err != nil {
logit.Error.Println("GetStatus: " + err.Error())
rest.Error(w, err.Error(), 400)
return
}
w.WriteHeader(http.StatusOK)
w.WriteJson(stat)
}
示例14: GetSchedule
func GetSchedule(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println("BackupNow: error " + err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println("GetSchedule: validate token error " + err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
rest.Error(w, "ID required", 400)
return
}
result, err := backup.GetSchedule(dbConn, ID)
if err != nil {
logit.Error.Println("GetNode: " + err.Error())
rest.Error(w, err.Error(), 400)
return
}
w.WriteJson(result)
}
示例15: GetServer
// GetServer return a server definition
func GetServer(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
//logit.Info.Println("in GetServer with ID=" + ID)
//currently no state about a server is maintained other than IP and port number
//which we use for the ID, Name, and IPAddress values
server := types.Server{ID, ID, ID, ID, "", "", ""}
w.WriteJson(&server)
}