1*9bb1b549SSpandan Das<!-- Generated with Stardoc: http://skydoc.bazel.build --> 2*9bb1b549SSpandan Das 3*9bb1b549SSpandan Das 4*9bb1b549SSpandan Das [gazelle rule]: https://github.com/bazelbuild/bazel-gazelle#bazel-rule 5*9bb1b549SSpandan Das [golang/mock]: https://github.com/golang/mock 6*9bb1b549SSpandan Das [core go rules]: /docs/go/core/rules.md 7*9bb1b549SSpandan Das 8*9bb1b549SSpandan Das# Extra rules 9*9bb1b549SSpandan Das 10*9bb1b549SSpandan DasThis is a collection of helper rules. These are not core to building a go binary, but are supplied 11*9bb1b549SSpandan Dasto make life a little easier. 12*9bb1b549SSpandan Das 13*9bb1b549SSpandan Das## Contents 14*9bb1b549SSpandan Das- [gazelle](#gazelle) 15*9bb1b549SSpandan Das- [gomock](#gomock) 16*9bb1b549SSpandan Das- [go_embed_data](#go_embed_data) 17*9bb1b549SSpandan Das 18*9bb1b549SSpandan Das## Additional resources 19*9bb1b549SSpandan Das- [gazelle rule] 20*9bb1b549SSpandan Das- [golang/mock] 21*9bb1b549SSpandan Das- [core go rules] 22*9bb1b549SSpandan Das 23*9bb1b549SSpandan Das------------------------------------------------------------------------ 24*9bb1b549SSpandan Das 25*9bb1b549SSpandan Dasgazelle 26*9bb1b549SSpandan Das------- 27*9bb1b549SSpandan Das 28*9bb1b549SSpandan DasThis rule has moved. See [gazelle rule] in the Gazelle repository. 29*9bb1b549SSpandan Das 30*9bb1b549SSpandan Das 31*9bb1b549SSpandan Das 32*9bb1b549SSpandan Das 33*9bb1b549SSpandan Das 34*9bb1b549SSpandan Das 35*9bb1b549SSpandan Das<a id="#go_embed_data"></a> 36*9bb1b549SSpandan Das 37*9bb1b549SSpandan Das## go_embed_data 38*9bb1b549SSpandan Das 39*9bb1b549SSpandan Das<pre> 40*9bb1b549SSpandan Dasgo_embed_data(<a href="#go_embed_data-name">name</a>, <a href="#go_embed_data-flatten">flatten</a>, <a href="#go_embed_data-package">package</a>, <a href="#go_embed_data-src">src</a>, <a href="#go_embed_data-srcs">srcs</a>, <a href="#go_embed_data-string">string</a>, <a href="#go_embed_data-unpack">unpack</a>, <a href="#go_embed_data-var">var</a>) 41*9bb1b549SSpandan Das</pre> 42*9bb1b549SSpandan Das 43*9bb1b549SSpandan Das**Deprecated**: Will be removed in rules_go 0.39. 44*9bb1b549SSpandan Das 45*9bb1b549SSpandan Das`go_embed_data` generates a .go file that contains data from a file or a 46*9bb1b549SSpandan Daslist of files. It should be consumed in the srcs list of one of the 47*9bb1b549SSpandan Das[core go rules]. 48*9bb1b549SSpandan Das 49*9bb1b549SSpandan DasBefore using `go_embed_data`, you must add the following snippet to your 50*9bb1b549SSpandan DasWORKSPACE: 51*9bb1b549SSpandan Das 52*9bb1b549SSpandan Das``` bzl 53*9bb1b549SSpandan Dasload("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependencies") 54*9bb1b549SSpandan Das 55*9bb1b549SSpandan Dasgo_embed_data_dependencies() 56*9bb1b549SSpandan Das``` 57*9bb1b549SSpandan Das 58*9bb1b549SSpandan Das`go_embed_data` accepts the attributes listed below. 59*9bb1b549SSpandan Das 60*9bb1b549SSpandan Das 61*9bb1b549SSpandan Das### **Attributes** 62*9bb1b549SSpandan Das 63*9bb1b549SSpandan Das 64*9bb1b549SSpandan Das| Name | Description | Type | Mandatory | Default | 65*9bb1b549SSpandan Das| :------------- | :------------- | :------------- | :------------- | :------------- | 66*9bb1b549SSpandan Das| <a id="go_embed_data-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 67*9bb1b549SSpandan Das| <a id="go_embed_data-flatten"></a>flatten | If <code>True</code> and <code>srcs</code> is used, map keys are file base names instead of relative paths. | Boolean | optional | False | 68*9bb1b549SSpandan Das| <a id="go_embed_data-package"></a>package | Go package name for the generated .go file. | String | optional | "" | 69*9bb1b549SSpandan Das| <a id="go_embed_data-src"></a>src | A single file to embed. This cannot be used at the same time as <code>srcs</code>. The generated file will have a variable of type <code>[]byte</code> or <code>string</code> with the contents of this file. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | None | 70*9bb1b549SSpandan Das| <a id="go_embed_data-srcs"></a>srcs | A list of files to embed. This cannot be used at the same time as <code>src</code>. The generated file will have a variable of type <code>map[string][]byte</code> or <code>map[string]string</code> with the contents of each file. The map keys are relative paths of the files from the repository root. Keys for files in external repositories will be prefixed with <code>"external/repo/"</code> where "repo" is the name of the external repository. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | [] | 71*9bb1b549SSpandan Das| <a id="go_embed_data-string"></a>string | If <code>True</code>, the embedded data will be stored as <code>string</code> instead of <code>[]byte</code>. | Boolean | optional | False | 72*9bb1b549SSpandan Das| <a id="go_embed_data-unpack"></a>unpack | If <code>True</code>, sources are treated as archives and their contents will be stored. Supported formats are <code>.zip</code> and <code>.tar</code> | Boolean | optional | False | 73*9bb1b549SSpandan Das| <a id="go_embed_data-var"></a>var | Name of the variable that will contain the embedded data. | String | optional | "Data" | 74*9bb1b549SSpandan Das 75*9bb1b549SSpandan Das 76*9bb1b549SSpandan Das<a id="gomock"></a> 77*9bb1b549SSpandan Das 78*9bb1b549SSpandan Das## gomock 79*9bb1b549SSpandan Das 80*9bb1b549SSpandan Das<pre> 81*9bb1b549SSpandan Dasgomock(<a href="#gomock-name">name</a>, <a href="#gomock-library">library</a>, <a href="#gomock-out">out</a>, <a href="#gomock-source">source</a>, <a href="#gomock-interfaces">interfaces</a>, <a href="#gomock-package">package</a>, <a href="#gomock-self_package">self_package</a>, <a href="#gomock-aux_files">aux_files</a>, <a href="#gomock-mockgen_tool">mockgen_tool</a>, 82*9bb1b549SSpandan Das <a href="#gomock-imports">imports</a>, <a href="#gomock-copyright_file">copyright_file</a>, <a href="#gomock-mock_names">mock_names</a>, <a href="#gomock-kwargs">kwargs</a>) 83*9bb1b549SSpandan Das</pre> 84*9bb1b549SSpandan Das 85*9bb1b549SSpandan DasCalls [mockgen](https://github.com/golang/mock) to generates a Go file containing mocks from the given library. 86*9bb1b549SSpandan Das 87*9bb1b549SSpandan DasIf `source` is given, the mocks are generated in source mode; otherwise in reflective mode. 88*9bb1b549SSpandan Das 89*9bb1b549SSpandan Das 90*9bb1b549SSpandan Das**PARAMETERS** 91*9bb1b549SSpandan Das 92*9bb1b549SSpandan Das 93*9bb1b549SSpandan Das| Name | Description | Default Value | 94*9bb1b549SSpandan Das| :------------- | :------------- | :------------- | 95*9bb1b549SSpandan Das| <a id="gomock-name"></a>name | the target name. | none | 96*9bb1b549SSpandan Das| <a id="gomock-library"></a>library | the Go library to took for the interfaces (reflecitve mode) or source (source mode). | none | 97*9bb1b549SSpandan Das| <a id="gomock-out"></a>out | the output Go file name. | none | 98*9bb1b549SSpandan Das| <a id="gomock-source"></a>source | a Go file in the given <code>library</code>. If this is given, <code>gomock</code> will call mockgen in source mode to mock all interfaces in the file. | <code>None</code> | 99*9bb1b549SSpandan Das| <a id="gomock-interfaces"></a>interfaces | a list of interfaces in the given <code>library</code> to be mocked in reflective mode. | <code>[]</code> | 100*9bb1b549SSpandan Das| <a id="gomock-package"></a>package | the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See [mockgen's -package](https://github.com/golang/mock#flags) for more information. | <code>""</code> | 101*9bb1b549SSpandan Das| <a id="gomock-self_package"></a>self_package | the full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. See [mockgen's -self_package](https://github.com/golang/mock#flags) for more information. | <code>""</code> | 102*9bb1b549SSpandan Das| <a id="gomock-aux_files"></a>aux_files | a map from source files to their package path. This only needed when <code>source</code> is provided. See [mockgen's -aux_files](https://github.com/golang/mock#flags) for more information. | <code>{}</code> | 103*9bb1b549SSpandan Das| <a id="gomock-mockgen_tool"></a>mockgen_tool | the mockgen tool to run. | <code>Label("//extras/gomock:mockgen")</code> | 104*9bb1b549SSpandan Das| <a id="gomock-imports"></a>imports | dictionary of name-path pairs of explicit imports to use. See [mockgen's -imports](https://github.com/golang/mock#flags) for more information. | <code>{}</code> | 105*9bb1b549SSpandan Das| <a id="gomock-copyright_file"></a>copyright_file | optional file containing copyright to prepend to the generated contents. See [mockgen's -copyright_file](https://github.com/golang/mock#flags) for more information. | <code>None</code> | 106*9bb1b549SSpandan Das| <a id="gomock-mock_names"></a>mock_names | dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See [mockgen's -mock_names](https://github.com/golang/mock#flags) for more information. | <code>{}</code> | 107*9bb1b549SSpandan Das| <a id="gomock-kwargs"></a>kwargs | <p align="center"> - </p> | none | 108*9bb1b549SSpandan Das 109*9bb1b549SSpandan Das 110