• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang auth.GetTokenFromContext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: aggregatesHandler

// Aggregates
func (u *Uchiwa) aggregatesHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	// verify that the authenticated user is authorized to access this resource
	token := auth.GetTokenFromContext(r)

	resources := strings.Split(r.URL.Path, "/")

	if len(resources) == 2 {
		token := auth.GetTokenFromContext(r)
		aggregates := FilterAggregates(&u.Data.Aggregates, token)

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(aggregates); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	} else if len(resources) == 5 {
		check := resources[3]
		dc := resources[2]
		issued := resources[4]

		if check == "" || dc == "" || issued == "" {
			http.Error(w, "", http.StatusBadRequest)
			return
		}

		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		aggregate, err := u.GetAggregateByIssued(check, issued, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), 500)
			return
		}

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(aggregate); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	} else {
		http.Error(w, "", http.StatusBadRequest)
		return
	}
}
开发者ID:postfix,项目名称:uchiwa,代码行数:53,代码来源:server.go


示例2: getAggregateByIssuedHandler

func (u *Uchiwa) getAggregateByIssuedHandler(w http.ResponseWriter, r *http.Request) {
	urlStruct, _ := url.Parse(r.URL.String())
	check := urlStruct.Query().Get("check")
	issued := urlStruct.Query().Get("issued")
	dc := urlStruct.Query().Get("dc")
	if check == "" || issued == "" || dc == "" {
		http.Error(w, fmt.Sprint("Parameters 'check', 'issued' and 'dc' are required"), http.StatusNotFound)
		return
	}

	// verify that the authenticated user is authorized to access this resource
	token := auth.GetTokenFromContext(r)
	unauthorized := FilterGetRequest(dc, token)

	if unauthorized {
		http.Error(w, fmt.Sprint(""), http.StatusNotFound)
		return
	}

	aggregate, err := u.GetAggregateByIssued(check, issued, dc)
	if err != nil {
		http.Error(w, fmt.Sprint(err), 500)
	} else {
		encoder := json.NewEncoder(w)
		if err := encoder.Encode(aggregate); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
		}
	}
}
开发者ID:traviswdev,项目名称:uchiwa,代码行数:29,代码来源:server.go


示例3: getClientHandler

func (u *Uchiwa) getClientHandler(w http.ResponseWriter, r *http.Request) {
	urlStruct, _ := url.Parse(r.URL.String())
	id := urlStruct.Query().Get("id")
	dc := urlStruct.Query().Get("dc")
	if id == "" || dc == "" {
		http.Error(w, fmt.Sprint("Parameters 'id' and 'dc' are required"), http.StatusNotFound)
		return
	}

	// verify that the authenticated user is authorized to access this resource
	token := auth.GetTokenFromContext(r)
	unauthorized := FilterGetRequest(dc, token)

	if unauthorized {
		http.Error(w, fmt.Sprint(""), http.StatusNotFound)
		return
	}

	client, err := u.GetClient(id, dc)
	if err != nil {
		http.Error(w, fmt.Sprint(err), http.StatusNotFound)
		return
	}

	encoder := json.NewEncoder(w)
	if err := encoder.Encode(client); err != nil {
		http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
		return
	}
}
开发者ID:jsoriano,项目名称:uchiwa,代码行数:30,代码来源:server.go


示例4: resultsHandler

// Results
func (u *Uchiwa) resultsHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "DELETE" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	resources := strings.Split(r.URL.Path, "/")
	if len(resources) != 5 {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	check := resources[4]
	client := resources[3]
	dc := resources[2]

	token := auth.GetTokenFromContext(r)

	unauthorized := FilterGetRequest(dc, token)
	if unauthorized {
		http.Error(w, fmt.Sprint(""), http.StatusNotFound)
		return
	}

	err := u.DeleteCheckResult(check, client, dc)
	if err != nil {
		http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
		return
	}
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:31,代码来源:server.go


示例5: stashHandler

func (u *Uchiwa) stashHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	decoder := json.NewDecoder(r.Body)
	var data stash
	err := decoder.Decode(&data)
	if err != nil {
		http.Error(w, "Could not decode body", http.StatusInternalServerError)
		return
	}

	// verify that the authenticated user is authorized to access this resource
	token := auth.GetTokenFromContext(r)
	unauthorized := FilterGetRequest(data.Dc, token)

	// add username to the stash content
	if token != nil && token.Claims["Username"] != nil {
		data.Content["username"] = token.Claims["Username"]
	}

	if unauthorized {
		http.Error(w, fmt.Sprint(""), http.StatusNotFound)
		return
	}

	err = u.PostStash(data)
	if err != nil {
		http.Error(w, "Could not create the stash", http.StatusNotFound)
	}
}
开发者ID:traviswdev,项目名称:uchiwa,代码行数:33,代码来源:server.go


示例6: requestHandler

// Request
func (u *Uchiwa) requestHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	decoder := json.NewDecoder(r.Body)
	var data structs.CheckExecution
	err := decoder.Decode(&data)
	if err != nil {
		http.Error(w, "Could not decode body", http.StatusInternalServerError)
		return
	}

	// verify that the authenticated user is authorized to access this resource
	token := auth.GetTokenFromContext(r)
	unauthorized := FilterGetRequest(data.Dc, token)
	if unauthorized {
		http.Error(w, fmt.Sprint(""), http.StatusNotFound)
		return
	}

	err = u.IssueCheckExecution(data)
	if err != nil {
		http.Error(w, "Could not create the stash", http.StatusNotFound)
		return
	}

	return
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:31,代码来源:server.go


示例7: stashesHandler

// Stashes
func (u *Uchiwa) stashesHandler(w http.ResponseWriter, r *http.Request) {
	token := auth.GetTokenFromContext(r)
	resources := strings.Split(r.URL.Path, "/")

	if r.Method == "DELETE" && len(resources) >= 3 {
		dc := resources[2]
		path := strings.Join(resources[3:], "/")

		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		err := u.DeleteStash(dc, path)
		if err != nil {
			http.Error(w, "Could not create the stash", http.StatusNotFound)
		}
	} else if r.Method == "GET" {
		stashes := FilterStashes(&u.Data.Stashes, token)

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(stashes); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	} else if r.Method == "POST" {
		decoder := json.NewDecoder(r.Body)
		var data stash
		err := decoder.Decode(&data)
		if err != nil {
			http.Error(w, "Could not decode body", http.StatusInternalServerError)
			return
		}

		// verify that the authenticated user is authorized to access this resource
		unauthorized := FilterGetRequest(data.Dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		if token != nil && token.Claims["Username"] != nil {
			data.Content["username"] = token.Claims["Username"]
		}

		err = u.PostStash(data)
		if err != nil {
			http.Error(w, "Could not create the stash", http.StatusNotFound)
			return
		}
	} else {
		http.Error(w, "", http.StatusBadRequest)
		return
	}
}
开发者ID:postfix,项目名称:uchiwa,代码行数:57,代码来源:server.go


示例8: getSensuHandler

func (u *Uchiwa) getSensuHandler(w http.ResponseWriter, r *http.Request) {
	//Test()
	token := auth.GetTokenFromContext(r)
	data := FilterSensuData(token, u.Data)

	encoder := json.NewEncoder(w)
	if err := encoder.Encode(data); err != nil {
		http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
	}
}
开发者ID:traviswdev,项目名称:uchiwa,代码行数:10,代码来源:server.go


示例9: stashesHandler

// stashes
func (u *Uchiwa) stashesHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		token := auth.GetTokenFromContext(r)
		stashes := FilterStashes(&u.Data.Stashes, token)

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(stashes); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	} else if r.Method == "POST" {
		decoder := json.NewDecoder(r.Body)
		var data stash
		err := decoder.Decode(&data)
		if err != nil {
			http.Error(w, "Could not decode body", http.StatusInternalServerError)
			return
		}

		// verify that the authenticated user is authorized to access this resource
		token := auth.GetTokenFromContext(r)
		unauthorized := FilterGetRequest(data.Dc, token)

		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		err = u.PostStash(data)
		if err != nil {
			http.Error(w, "Could not create the stash", http.StatusNotFound)
			return
		}
	} else {
		http.Error(w, "", http.StatusBadRequest)
		return
	}
}
开发者ID:jsoriano,项目名称:uchiwa,代码行数:39,代码来源:server.go


示例10: subscriptionsHandler

// Subscriptions
func (u *Uchiwa) subscriptionsHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	token := auth.GetTokenFromContext(r)
	subscriptions := FilterSubscriptions(&u.Data.Subscriptions, token)

	encoder := json.NewEncoder(w)
	if err := encoder.Encode(subscriptions); err != nil {
		http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
		return
	}
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:16,代码来源:server.go


示例11: eventsHandler

// Events
func (u *Uchiwa) eventsHandler(w http.ResponseWriter, r *http.Request) {
	token := auth.GetTokenFromContext(r)

	// DELETE on /events
	if r.Method == "DELETE" {
		resources := strings.Split(r.URL.Path, "/")
		if len(resources) != 5 {
			http.Error(w, "", http.StatusBadRequest)
			return
		}

		check := resources[4]
		client := resources[3]
		dc := resources[2]

		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		err := u.ResolveEvent(check, client, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
			return
		}

	} else if r.Method == "GET" {
		// GET on /events
		events := FilterEvents(&u.Data.Events, token)

		// Create header
		w.Header().Add("Accept-Charset", "utf-8")
		w.Header().Add("Content-Type", "application/json")
		w.Header().Set("Content-Encoding", "gzip")

		gz := gzip.NewWriter(w)
		defer gz.Close()
		if err := json.NewEncoder(gz).Encode(events); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
		return
	} else {
		http.Error(w, "", http.StatusBadRequest)
		return
	}
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:49,代码来源:server.go


示例12: datacentersHandler

// Datacenters
func (u *Uchiwa) datacentersHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	token := auth.GetTokenFromContext(r)
	datacenters := FilterDatacenters(u.Data.Dc, token)

	// Create header
	w.Header().Add("Accept-Charset", "utf-8")
	w.Header().Add("Content-Type", "application/json")
	w.Header().Set("Content-Encoding", "gzip")

	gz := gzip.NewWriter(w)
	defer gz.Close()
	if err := json.NewEncoder(gz).Encode(datacenters); err != nil {
		http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
		return
	}
	return
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:23,代码来源:server.go


示例13: eventsHandler

// Events
func (u *Uchiwa) eventsHandler(w http.ResponseWriter, r *http.Request) {
	token := auth.GetTokenFromContext(r)

	if r.Method == "DELETE" {
		resources := strings.Split(r.URL.Path, "/")
		if len(resources) != 5 {
			http.Error(w, "", http.StatusBadRequest)
			return
		}

		check := resources[4]
		client := resources[3]
		dc := resources[2]

		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		err := u.ResolveEvent(check, client, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
			return
		}

	} else if r.Method == "GET" {
		events := FilterEvents(&u.Data.Events, token)

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(events); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	} else {
		http.Error(w, "", http.StatusBadRequest)
		return
	}
}
开发者ID:postfix,项目名称:uchiwa,代码行数:40,代码来源:server.go


示例14: postEventHandler

func (u *Uchiwa) postEventHandler(w http.ResponseWriter, r *http.Request) {
	decoder := json.NewDecoder(r.Body)
	var data interface{}
	err := decoder.Decode(&data)
	if err != nil {
		http.Error(w, fmt.Sprint("Could not decode body"), http.StatusInternalServerError)
		return
	}

	// verify that the authenticated user is authorized to access this resource
	token := auth.GetTokenFromContext(r)
	unauthorized := FilterPostRequest(token, &data)

	if unauthorized {
		http.Error(w, fmt.Sprint(""), http.StatusNotFound)
		return
	}

	err = u.ResolveEvent(data)

	if err != nil {
		http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
	}
}
开发者ID:traviswdev,项目名称:uchiwa,代码行数:24,代码来源:server.go


示例15: aggregatesHandler

// Aggregates
func (u *Uchiwa) aggregatesHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	// verify that the authenticated user is authorized to access this resource
	token := auth.GetTokenFromContext(r)

	resources := strings.Split(r.URL.Path, "/")

	// GET on /aggregates
	if len(resources) == 2 {
		token := auth.GetTokenFromContext(r)
		aggregates := FilterAggregates(&u.Data.Aggregates, token)

		// Create header
		w.Header().Add("Accept-Charset", "utf-8")
		w.Header().Add("Content-Type", "application/json")
		w.Header().Set("Content-Encoding", "gzip")

		gz := gzip.NewWriter(w)
		defer gz.Close()
		if err := json.NewEncoder(gz).Encode(aggregates); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
		return
	} else if len(resources) == 5 {
		// GET on /aggregates/{dc}/{check}/{issued}
		check := resources[3]
		dc := resources[2]
		issued := resources[4]

		if check == "" || dc == "" || issued == "" {
			http.Error(w, "", http.StatusBadRequest)
			return
		}

		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		aggregate, err := u.GetAggregateByIssued(check, issued, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), 500)
			return
		}

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(aggregate); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	} else {
		http.Error(w, "", http.StatusBadRequest)
		return
	}
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:62,代码来源:server.go


示例16: stashesHandler

// Stashes
func (u *Uchiwa) stashesHandler(w http.ResponseWriter, r *http.Request) {
	token := auth.GetTokenFromContext(r)
	resources := strings.Split(r.URL.Path, "/")

	// DELETE on /stashes/{dc}/{path}
	if r.Method == "DELETE" && len(resources) >= 3 {
		dc := resources[2]
		path := strings.Join(resources[3:], "/")

		if dc == "" || path == "" {
			http.Error(w, "", http.StatusBadRequest)
			return
		}

		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		err := u.DeleteStash(dc, path)
		if err != nil {
			logger.Warningf("Could not delete the stash '%s': %s", path, err)
			http.Error(w, "Could not create the stash", http.StatusNotFound)
			return
		}
	} else if r.Method == "GET" {
		// GET on /stashes
		stashes := FilterStashes(&u.Data.Stashes, token)

		// Create header
		w.Header().Add("Accept-Charset", "utf-8")
		w.Header().Add("Content-Type", "application/json")
		w.Header().Set("Content-Encoding", "gzip")

		gz := gzip.NewWriter(w)
		defer gz.Close()
		if err := json.NewEncoder(gz).Encode(stashes); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
		return
	} else if r.Method == "POST" {
		// POST on /stashes
		decoder := json.NewDecoder(r.Body)
		var data stash
		err := decoder.Decode(&data)
		if err != nil {
			http.Error(w, "Could not decode body", http.StatusInternalServerError)
			return
		}

		// verify that the authenticated user is authorized to access this resource
		unauthorized := FilterGetRequest(data.Dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		if token != nil && token.Claims["Username"] != nil {
			data.Content["username"] = token.Claims["Username"]
		}

		err = u.PostStash(data)
		if err != nil {
			http.Error(w, "Could not create the stash", http.StatusNotFound)
			return
		}
	} else {
		http.Error(w, "", http.StatusBadRequest)
		return
	}
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:74,代码来源:server.go


示例17: clientsHandler

// Clients
func (u *Uchiwa) clientsHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "DELETE" && r.Method != "GET" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	token := auth.GetTokenFromContext(r)

	resources := strings.Split(r.URL.Path, "/")

	// GET on /clients
	if len(resources) == 2 && r.Method == "GET" {
		clients := FilterClients(&u.Data.Clients, token)

		// Create header
		w.Header().Add("Accept-Charset", "utf-8")
		w.Header().Add("Content-Type", "application/json")
		w.Header().Set("Content-Encoding", "gzip")

		gz := gzip.NewWriter(w)
		defer gz.Close()
		if err := json.NewEncoder(gz).Encode(clients); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
		return
	} else if len(resources) != 4 {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	client := resources[3]
	dc := resources[2]

	if client == "" || dc == "" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	// DELETE on /clients
	if r.Method == "DELETE" {
		// verify that the authenticated user is authorized to access this resource
		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		err := u.DeleteClient(client, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
			return
		}
	} else if r.Method == "GET" {
		// GET on /clients/{client}
		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		data, err := u.GetClient(client, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), http.StatusNotFound)
			return
		}

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(data); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	}
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:75,代码来源:server.go


示例18: clientsHandler

// Clients
func (u *Uchiwa) clientsHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "DELETE" && r.Method != "GET" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	token := auth.GetTokenFromContext(r)

	resources := strings.Split(r.URL.Path, "/")
	if len(resources) == 2 && r.Method == "GET" {
		clients := FilterClients(&u.Data.Clients, token)
		encoder := json.NewEncoder(w)
		if err := encoder.Encode(clients); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
		return
	} else if len(resources) != 4 {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	client := resources[3]
	dc := resources[2]

	if client == "" || dc == "" {
		http.Error(w, "", http.StatusBadRequest)
		return
	}

	if r.Method == "DELETE" {
		// verify that the authenticated user is authorized to access this resource
		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		err := u.DeleteClient(client, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
			return
		}
	} else if r.Method == "GET" {
		unauthorized := FilterGetRequest(dc, token)
		if unauthorized {
			http.Error(w, fmt.Sprint(""), http.StatusNotFound)
			return
		}

		data, err := u.GetClient(client, dc)
		if err != nil {
			http.Error(w, fmt.Sprint(err), http.StatusNotFound)
			return
		}

		encoder := json.NewEncoder(w)
		if err := encoder.Encode(data); err != nil {
			http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
			return
		}
	}
}
开发者ID:postfix,项目名称:uchiwa,代码行数:64,代码来源:server.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang auth.Config类代码示例发布时间:2022-05-28
下一篇:
Golang go-kinesis.Kinesis类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap