gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/route_types.go (about) 1 package ign 2 3 import ( 4 "net/http" 5 ) 6 7 // Route is a definition of a route 8 type Route struct { 9 10 // Name of the route 11 Name string `json:"name"` 12 13 // Description of the route 14 Description string `json:"description"` 15 16 // URI pattern 17 URI string `json:"uri"` 18 19 // Headers required by the route 20 Headers []Header `json:"headers"` 21 22 // HTTP methods supported by the route 23 Methods Methods `json:"methods"` 24 25 // Secure HTTP methods supported by the route 26 SecureMethods SecureMethods `json:"secure_methods"` 27 } 28 29 // Routes is an array of Route 30 type Routes []Route 31 32 // Header stores the information about headers included in a request. 33 type Header struct { 34 Name string `json:"name"` 35 HeaderDetails Detail `json:"details"` 36 } 37 38 // Detail stores information about a paramter. 39 type Detail struct { 40 Type string `json:"type"` 41 Description string `json:"description"` 42 Required bool `json:"required"` 43 } 44 45 // Method associates an HTTP method (GET, POST, PUT, DELETE) with a list of 46 // handlers. 47 type Method struct { 48 // GET, POST, PUT, DELETE 49 // \todo: Make this an enum 50 Type string `json:"type"` 51 52 // Description of the method 53 Description string `json:"description"` 54 55 // A slice of hanlders used to process this method. 56 Handlers FormatHandlers `json:"handler"` 57 } 58 59 // Methods is a slice of Method. 60 type Methods []Method 61 62 // SecureMethods is a slice of Method that require authentication. 63 type SecureMethods []Method 64 65 // FormatHandler represents a format type string, and handler function pair. Handlers are called in response to a route request. 66 type FormatHandler struct { 67 // Format (eg: .json, .proto, .html) 68 Extension string `json:"extension"` 69 70 // Processor for the url pattern 71 Handler http.Handler `json:"-"` 72 } 73 74 // FormatHandlers is a slice of FormatHandler values. 75 type FormatHandlers []FormatHandler 76 77 // AuthHeadersRequired is an array of Headers needed when authentication is 78 // required. 79 var AuthHeadersRequired = []Header{ 80 { 81 Name: "authorization: Bearer <YOUR_JWT_TOKEN>", 82 HeaderDetails: Detail{ 83 Required: true, 84 }, 85 }, 86 } 87 88 // AuthHeadersOptional is an array of Headers needed when authentication is 89 // optional. 90 var AuthHeadersOptional = []Header{ 91 { 92 Name: "authorization: Bearer <YOUR_JWT_TOKEN>", 93 HeaderDetails: Detail{ 94 Required: false, 95 }, 96 }, 97 }