goutilh

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package goutilh provides functions for generating Go code. It can be used in utilities for go:generate, such as including any file at compile time into project as []byte or duplicate existing Go code with some modification (some kind of generics/macros).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteBytes

func WriteBytes(b []byte, w io.Writer, array bool) error

WriteBytes convert given slice of bytes to GoLang source code representation and write it to given io.Writer. Result will be representation of array type if passed array is true. Otherwise representation will be of type slice. Example: for b=[]byte{1, 2, 3} WriteBytesStr will write "[]byte{1, 2, 3}" AS STRING if array is false and "[3]byte{1, 2, 3}" if array is true. This function may be useful with "//go:generate" directive to include some (binary) files into app at compile time. There are 2 different implementations of this function: using "go/asth" and generating representation "by hand". WriteBytes decides at runtime which implementation to use depending on len(b).

func WriteBytesAst

func WriteBytesAst(b []byte, w io.Writer, array bool) error

WriteBytesAst is Ast (see go/asth) implementation of WriteBytes. It should generate proper code even if minor changes in language will happened, but its speed and resource consumption is poor.

func WriteBytesStr

func WriteBytesStr(b []byte, w io.Writer, array bool) error

WriteBytesStr is "by hand" implementation of WriteBytes. It should works quicker even with a large number of elements in b.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL