Categorygithub.com/allar/code
modulepackage
0.2.0
Repository: https://github.com/allar/code.git
Documentation: pkg.go.dev

# README

Code Go Report Card Coverage Status Build Status

Code is a small wrapper around jen that allows go-services to generate go code easier.

It has a very friendly api

package main

import (
    "github.com/go-services/code"
    "fmt"
)

func main() {
    structure := code.NewStruct("MyStruct")
    
    fmt.Println(structure) // 	type MyStruct struct{}

    structure.Fields = []code.StructField{
        code.NewStructField("Name", code.NewType("string")),
    }
    fmt.Println(structure)  // 	type MyStruct struct {
                            //  	Name string
                            //  }

}

# Functions

ArrayTypeOption marks the type as variadic.
BodyFunctionOption adds given body code to the function.
DocsFunctionOption adds given docs to the function.
FunctionTypeOption adds the given function type to the type.
ImportTypeOption adds the given import to the type.
NewComment creates a Comment with the given string.
NewConst creates a 7new constant with the given name type and value.
NewFieldTags creates a new field tags map with initial key and value.
NewFile creates a new file with the given package name and optional code nodes.
NewFunction creates a new function with the given name and options.
NewFunctionType creates a new function type with the given options.
NewImport creates a new Import with the given alias and path.
NewImportAlias creates a new import alias with the given name and path.
NewImportWithFilePath creates a new Import with the given alias and path and filepath.
NewInterface creates a new interface with the given name and methods, there is also an optional list of documentation comments that you can add to the variable.
NewInterfaceMethod creates a new interface method with the given name and options.
NewParameter creates a new parameter with the given name and type.
No description provided by the author
NewRawType creates a new type with raw jen statement.
NewStruct creates a new structure with the given name, there is also an optional list of documentation comments that you can add to the variable.
NewStructField creates a new structure field with the given name and type, there is also an optional list of documentation comments that you can add to the variable.
NewStructFieldWithTag creates a new structure field with the given name type and tags, there is also an optional list of documentation comments that you can add to the variable.
NewStructWithFields creates a new structure with the given name and fields, there is also an optional list of documentation comments that you can add to the variable.
NewType creates the type with the qualifier and options given.
NewVar creates a new var with the given name and type, there is also an optional list of documentation comments that you can add to the variable.
NewVarWithValue creates a new var with the given name type and value.
ParamsFunctionOption adds given parameters to the function.
PointerTypeOption marks the type as a pointer type.
RecvFunctionOption sets the function receiver.
ResultsFunctionOption adds given results to the function.
VariadicTypeOption marks the type as variadic.

# Structs

File represents a go source file.
Function represents a function.
Import represents an import this is mostly used for parameters and field types so we know what the package of the type is.
ImportAlias is used to specify the import alias in a file.
Interface is the representation of an interface.
Parameter represents a parameter, it is used in function parameters, function return parameters.
RawCode represents raw lines of code.
Struct represent a structure.
StructField represent a structure field, it uses the parameter representation to represent the name and the type the difference between parameter and struct field is that struct fields can have docs and tags.
Type represents a type e.x `string`, `context.Context`..
Var represents a variable.

# Interfaces

Code is the interface that all code nodes need to implement.

# Type aliases

Comment represents a code comment, it implements the Code interface.
Const represents a constant, it has the same attributes as the variable only that it assumes that the value is always set (there can not be any constant without initial value).
FieldTags represent the structure field tags (e.x `json:"test"`).
FunctionOptions is used when you call NewFunction, it is a handy way to allow multiple configurations for a function.
FunctionType is used in Type to specify a method type (e.x func(sting) int).
InterfaceMethod is the representation of interface methods (e.x String() string).
TypeOptions is used when you call NewType, it is a handy way to allow multiple configurations for a type.