Documentation ¶
Overview ¶
Example (GetPermissionsForURI) ¶
var a AuthMiddleWareData a.Logger = &logger.StdOutLogger{} a.RoutePermissionsRequired = map[string]string{ "GET/the/{id}/something": "root3", "GET/the/path": "root1", "POST/the/path": "root1a", "PUT/the/path/something": "root2", } fmt.Println(a.getPermissionsForURI("GET", "/the/121/something")) fmt.Println(a.getPermissionsForURI("GET", "/the/path")) fmt.Println(a.getPermissionsForURI("PUT", "/the/path/something")) fmt.Println(a.getPermissionsForURI("GET", "/the/121/path")) fmt.Println(a.getPermissionsForURI("GET", "/the/121/path/another")) fmt.Println(a.getPermissionsForURI("GET", "/")) fmt.Println(a.getPermissionsForURI("GET", "/obj")) fmt.Println(a.getPermissionsForURI("POST", "/the/path")) fmt.Println(a.getPermissionsForURI("PUT", "/the/121/something"))
Output: root3 <nil> root1 <nil> root2 <nil> Permissions not defined for route: GET /the/121/path Permissions not defined for route: GET /the/121/path/another Permissions not defined for route: GET / Permissions not defined for route: GET /obj root1a <nil> Permissions not defined for route: PUT /the/121/something
Example (IsMatch) ¶
// Matches fmt.Println(isMatch("GET/roi", "GET/roi")) fmt.Println(isMatch("GET/roi/", "GET/roi")) fmt.Println(isMatch("GET/roi", "GET/roi/")) fmt.Println(isMatch("GET/roi/", "GET/roi/")) fmt.Println(isMatch("PUT/roi/123", "PUT/roi/{cat}")) fmt.Println(isMatch("PUT/roi/123/", "PUT/roi/{cat}")) fmt.Println(isMatch("PUT/roi/123", "PUT/roi/{cat}/")) fmt.Println(isMatch("PUT/roi/123/", "PUT/roi/{cat}/")) fmt.Println(isMatch("POST/roi/123/999", "POST/roi/{cat}/{id}")) fmt.Println(isMatch("POST/roi/123/999/", "POST/roi/{cat}/{id}")) fmt.Println(isMatch("POST/roi/123/999", "POST/roi/{cat}/{id}/")) fmt.Println(isMatch("POST/roi/123/999/", "POST/roi/{cat}/{id}/")) fmt.Println(isMatch("DELETE/roi/123/path", "DELETE/roi/{cat}/path")) fmt.Println(isMatch("DELETE/roi/123/path/", "DELETE/roi/{cat}/path")) fmt.Println(isMatch("DELETE/roi/123/path", "DELETE/roi/{cat}/path/")) fmt.Println(isMatch("DELETE/roi/123/path/", "DELETE/roi/{cat}/path/")) fmt.Println(isMatch("GET/roi/123/path/999", "GET/roi/{cat}/path/{id}")) fmt.Println(isMatch("GET/roi/123/path/999/", "GET/roi/{cat}/path/{id}")) fmt.Println(isMatch("GET/roi/123/path/999", "GET/roi/{cat}/path/{id}/")) fmt.Println(isMatch("GET/roi/123/path/999/", "GET/roi/{cat}/path/{id}/")) // Fails fmt.Println(isMatch("/roi", "/roi")) fmt.Println(isMatch("SAVE/roi", "SAVE/roi")) fmt.Println(isMatch("GET/", "GET/roi")) fmt.Println(isMatch("GET/roi", "GET/roi/{cat}")) fmt.Println(isMatch("GET/roi/", "GET/roi/{cat}")) fmt.Println(isMatch("GET/roi/999", "GET/roi/{cat}/{id}")) fmt.Println(isMatch("GET/roi/999/", "GET/roi/{cat}/{id}")) fmt.Println(isMatch("GET/roi/999/", "GET/roi/{cat}/path/{id}")) fmt.Println(isMatch("GET/roi/999/path", "GET/roi/{cat}/path/{id}")) fmt.Println(isMatch("GET/roi/999/path/", "GET/roi/{cat}/path/{id}")) fmt.Println(isMatch("GET/roi/999/pathy/11", "GET/roi/{cat}/path/{id}"))
Output: true true true true true true true true true true true true true true true true true true true true false false false false false false false false false false false
Example (Version) ¶
var mockS3 awsutil.MockS3Client defer mockS3.FinishTest() svcs := MakeMockSvcs(&mockS3, nil, nil) apiRouter := apiRouter.NewAPIRouter(&svcs, mux.NewRouter()) apiRouter.AddPublicHandler("/", "GET", RootRequest) apiRouter.AddPublicHandler("/version-binary", "GET", GetVersionProtobuf) apiRouter.AddPublicHandler("/version-json", "GET", GetVersionJSON) req, _ := http.NewRequest("GET", "/", nil) resp := executeRequest(req, apiRouter.Router) fmt.Println(resp.Code) fmt.Println(strings.HasPrefix(string(resp.Body.Bytes()), "<!DOCTYPE html>")) versionPat := regexp.MustCompile(`<h1>PIXLISE API</h1><p>Version .+</p>`) fmt.Println(versionPat.MatchString(string(resp.Body.Bytes()))) req, _ = http.NewRequest("GET", "/version-json", nil) resp = executeRequest(req, apiRouter.Router) fmt.Println(resp.Code) // Don't know why but sometimes this passes, then it fails because it's printed with "API", "version" or with the space // missing... so here we just remove all spaces fmt.Printf("%v\n", strings.ReplaceAll(resp.Body.String(), " ", ""))
Output: 200 true true 200 {"versions":[{"component":"API","version":"(Localbuild)"}]}
Index ¶
- Constants
- func GetImage(params apiRouter.ApiHandlerStreamParams) (*s3.GetObjectOutput, string, string, string, int, error)
- func GetVersionJSON(params apiRouter.ApiHandlerGenericPublicParams) error
- func GetVersionProtobuf(params apiRouter.ApiHandlerGenericPublicParams) error
- func PrometheusMiddleware(next http.Handler) http.Handler
- func PutScanData(params apiRouter.ApiHandlerGenericParams) error
- func RootRequest(params apiRouter.ApiHandlerGenericPublicParams) error
- type AuthMiddleWareData
- type LoggerMiddleware
Examples ¶
Constants ¶
View Source
const FileNameIdentifier = "filename"
View Source
const FormatIdentifier = "format"
View Source
const ScanIdentifier = "scan"
Variables ¶
This section is empty.
Functions ¶
func GetImage ¶
func GetImage(params apiRouter.ApiHandlerStreamParams) (*s3.GetObjectOutput, string, string, string, int, error)
func GetVersionJSON ¶
func GetVersionJSON(params apiRouter.ApiHandlerGenericPublicParams) error
func GetVersionProtobuf ¶
func GetVersionProtobuf(params apiRouter.ApiHandlerGenericPublicParams) error
func PutScanData ¶ added in v4.0.6
func PutScanData(params apiRouter.ApiHandlerGenericParams) error
This allows the client to upload large zip files of data to import. This call simply saves the data in S3, it DOES NOT actually run the import process! For that, a ScanUploadReq needs to be sent with the same scanID and file name as passed to this call - otherwise it'll fail.
func RootRequest ¶
func RootRequest(params apiRouter.ApiHandlerGenericPublicParams) error
Types ¶
type AuthMiddleWareData ¶
type AuthMiddleWareData struct { RoutePermissionsRequired map[string]string JWTValidator jwtparser.JWTInterface Logger logger.ILogger }
func (*AuthMiddleWareData) Middleware ¶
func (a *AuthMiddleWareData) Middleware(next http.Handler) http.Handler
type LoggerMiddleware ¶
type LoggerMiddleware struct { *services.APIServices JwtValidator jwtparser.JWTInterface }
func (*LoggerMiddleware) Middleware ¶
func (h *LoggerMiddleware) Middleware(next http.Handler) http.Handler
Click to show internal directories.
Click to hide internal directories.