Add generated file
This PR adds generated files under pkg/client and vendor folder.
This commit is contained in:
35
vendor/github.com/emicklei/go-restful/examples/restful-basic-authentication.go
generated
vendored
Normal file
35
vendor/github.com/emicklei/go-restful/examples/restful-basic-authentication.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// This example shows how to create a (Route) Filter that performs Basic Authentication on the Http request.
|
||||
//
|
||||
// GET http://localhost:8080/secret
|
||||
// and use admin,admin for the credentials
|
||||
|
||||
func main() {
|
||||
ws := new(restful.WebService)
|
||||
ws.Route(ws.GET("/secret").Filter(basicAuthenticate).To(secret))
|
||||
restful.Add(ws)
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
||||
func basicAuthenticate(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
|
||||
// usr/pwd = admin/admin
|
||||
u, p, ok := req.Request.BasicAuth()
|
||||
if !ok || u != "admin" || p != "admin" {
|
||||
resp.AddHeader("WWW-Authenticate", "Basic realm=Protected Area")
|
||||
resp.WriteErrorString(401, "401: Not Authorized")
|
||||
return
|
||||
}
|
||||
chain.ProcessFilter(req, resp)
|
||||
}
|
||||
|
||||
func secret(req *restful.Request, resp *restful.Response) {
|
||||
io.WriteString(resp, "42")
|
||||
}
|
Reference in New Issue
Block a user