Documentation
¶
Index ¶
Constants ¶
const ExternsFilename = "barcode-cty-func/externs.cty"
ExternsFilename is the name reported for the embedded declarations in diagnostics.
Variables ¶
var BarcodeFunc = function.New(&function.Spec{ Description: "Generates a barcode image as a bytes object with content_type image/png", Params: []function.Parameter{ { Name: "type", Type: cty.String, Description: "Barcode symbology: \"qr\", \"datamatrix\", \"aztec\", \"pdf417\", \"code128\", \"code93\", \"code39\", \"codabar\", \"ean13\", \"ean8\", or \"2of5\"", }, { Name: "data", Type: cty.String, Description: "The data to encode. What is valid depends on the symbology: EAN-13 wants 12 or 13 digits, Code 39 an uppercase alphanumeric subset, QR anything.", }, }, VarParam: &function.Parameter{ Name: "options", Type: cty.DynamicPseudoType, AllowDynamicType: true, AllowNull: true, Description: "Optional object (at most one) with any of: " + "scale (positive integer, default 4), " + "width and height (positive integers, in pixels), " + "error_correction (\"L\", \"M\", \"Q\" or \"H\"; QR only, default \"M\"). " + "scale and width are mutually exclusive, and width requires height.", }, Type: func(args []cty.Value) (cty.Type, error) { if len(args) > 3 { return cty.NilType, fmt.Errorf("barcode() takes 2 or 3 arguments") } return bytescty.BytesObjectType, nil }, Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { btype := args[0].AsString() data := args[1].AsString() var optVal cty.Value if len(args) > 2 { optVal = args[2] } opts, err := parseBarcodeOptions(optVal, btype) if err != nil { return cty.NilVal, err } return encodeBarcode(btype, data, opts) }, })
BarcodeFunc generates a barcode image and returns it as a bytes object with content_type "image/png". Called as barcode(type, data) or barcode(type, data, options).
Functions ¶
func Externs ¶ added in v0.2.0
func Externs() []byte
Externs returns the functy `//functy:extern` declaration for the function GetBarcodeFunctions provides: its real signature, which its cty metadata cannot express.
The options object is *optional*, and the only way cty offers to make an argument optional is to make it variadic — which says it may be repeated, when it may not. cty also has no way to describe the object's shape, so it is declared dynamic: reflected from cty alone the function reads as `barcode(type, data, ...options)`, and what may go in that object is anybody's guess. The declaration gives it a name, a type, and its four attributes, so that help(), generated documentation, and editor tooling can show them.
The bytes are opaque to this package: it does not import functy, and nothing here parses them. A functy host registers them:
parser.RegisterExterns(barcodecty.Externs(), barcodecty.ExternsFilename)
func GetBarcodeFunctions ¶
GetBarcodeFunctions returns the barcode function set for registration in a cty evaluation context.
Types ¶
This section is empty.