Skip to content

Latest commit

 

History

History
executable file
·
76 lines (50 loc) · 3.83 KB

extras.md

File metadata and controls

executable file
·
76 lines (50 loc) · 3.83 KB

Extra rules

This is a collection of helper rules. These are not core to building a go binary, but are supplied to make life a little easier.

Contents

Additional resources


gazelle

This rule has moved. See gazelle rule in the Gazelle repository.

gomock

This rule allows you to generate mock interfaces with mockgen (from golang/mock) which can be useful for certain testing scenarios. See gomock_rule in the gomock repository.

go_embed_data

go_embed_data(name, flatten, package, src, srcs, string, unpack, var)

go_embed_data generates a .go file that contains data from a file or a list of files. It should be consumed in the srcs list of one of the core go rules.

Before using go_embed_data, you must add the following snippet to your WORKSPACE:

load("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependencies")

go_embed_data_dependencies()

go_embed_data accepts the attributes listed below.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
flatten If True and srcs is used, map keys are file base names instead of relative paths. Boolean optional False
package Go package name for the generated .go file. String optional ""
src A single file to embed. This cannot be used at the same time as srcs. The generated file will have a variable of type []byte or string with the contents of this file. Label optional None
srcs A list of files to embed. This cannot be used at the same time as src. The generated file will have a variable of type map[string][]byte or map[string]string 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 "external/repo/" where "repo" is the name of the external repository. List of labels optional []
string If True, the embedded data will be stored as string instead of []byte. Boolean optional False
unpack If True, sources are treated as archives and their contents will be stored. Supported formats are .zip and .tar Boolean optional False
var Name of the variable that will contain the embedded data. String optional "Data"