github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/plugins/prefix/README.md (about) 1 # Prefix Plugin 2 3 The prefix plugin is a micro toolkit plugin which strips a path prefix before continuing with the request 4 5 ## Usage 6 7 Register the plugin before building Micro 8 9 ``` 10 package main 11 12 import ( 13 "github.com/micro/micro/plugin" 14 "github.com/micro/go-micro/examples/plugins/prefix" 15 ) 16 17 func init() { 18 plugin.Register(prefix.NewPlugin()) 19 } 20 ``` 21 22 It can then be applied on the command line like so. 23 24 ``` 25 micro --path_prefix=/api api 26 ``` 27 28 ### Scoped to API 29 30 If you like to only apply the plugin for a specific component you can register it with that specifically. 31 For example, below you'll see the plugin registered with the API. 32 33 ``` 34 package main 35 36 import ( 37 "github.com/micro/micro/api" 38 "github.com/micro/go-micro/examples/plugins/prefix" 39 ) 40 41 func init() { 42 api.Register(prefix.NewPlugin()) 43 } 44 ``` 45 46 Here's what the help displays when you do that. 47 48 ``` 49 $ go run main.go plugin.go api --help 50 NAME: 51 main api - Run the micro API 52 53 USAGE: 54 main api [command options] [arguments...] 55 56 OPTIONS: 57 --address Set the api address e.g 0.0.0.0:8080 [$MICRO_API_ADDRESS] 58 --handler Specify the request handler to be used for mapping HTTP requests to services; {api, proxy, rpc} [$MICRO_API_HANDLER] 59 --namespace Set the namespace used by the API e.g. com.example.api [$MICRO_API_NAMESPACE] 60 --cors Comma separated whitelist of allowed origins for CORS [$MICRO_API_CORS] 61 --path_prefix Comma separated list of path prefixes to strip before continuing with request e.g /api,/foo,/bar [$PATH_PREFIX] 62 ``` 63 64 In this case the usage would be 65 66 ``` 67 micro api --path_prefix=/api 68 ```