types

package
v6.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomConjureType

type CustomConjureType struct {
	Name string
	// Pkg is the Go package that needs to be imported to use this type from an external package. Empty value
	// indicates that no import is needed (only true in cases where the Typer returns a Go primitive or built-in).
	Pkg string
	Typer
}

type CustomConjureTypes

type CustomConjureTypes interface {
	Add(name, pkg string, typer Typer) error
	Get(name string) (CustomConjureType, bool)
}

func NewCustomConjureTypes

func NewCustomConjureTypes() CustomConjureTypes

type PkgInfo

type PkgInfo struct {
	// contains filtered or unexported fields
}

func NewPkgInfo

func NewPkgInfo(currPkgPath string, customTypes CustomConjureTypes) PkgInfo

func (*PkgInfo) AddImports

func (i *PkgInfo) AddImports(imports ...string)

AddImports adds imports to the internal mapping tracking import paths and package aliases in the event of conflicts. Typer.GoType uses this map to correctly build the selector for an imported declaration.

func (*PkgInfo) CustomTypes

func (i *PkgInfo) CustomTypes() CustomConjureTypes

func (*PkgInfo) ImportAliases

func (i *PkgInfo) ImportAliases() map[string]string

ImportAliases returns a copy of the map of import paths to aliases. Modifications to the returned map will not be written to the PkgInfo.

func (*PkgInfo) SetImports

func (i *PkgInfo) SetImports(aliasString, importString string)

type Typer

type Typer interface {
	// GoType returns the string that can be used as the Go type declaration for this type. currPkg and pkgAliases
	// are used to determine the import paths that should be used to qualify the usage of type names. If a type
	// occurs in a package that matches currPkg, the package will not be referenced. Otherwise, if the package path
	// matches a key in the pkgAliases map, the package name of the value (which is the last portion of its import
	// path) will be used.
	//
	// As an example, if type "t" is a type alias named "ExampleAlias" defined in "github.com/palantir/generated/alias":
	//
	// * t.GoType("github.com/palantir/generated/alias", nil) -> ExampleAlias
	// * t.GoType("github.com/project", nil) -> alias.ExampleAlias
	// * t.GoType("github.com/project", map[string]string{"github.com/palantir/generated/alias": "pkgalias" }) -> pkgalias.ExampleAlias
	GoType(info PkgInfo) string

	// ImportPath returns the strings that can be used as the Go import path for this type. Returns an empty string
	// if the type is a primitive and does not require an import. We must return a list for all collection types
	ImportPaths() []string
}
var (
	String Typer = &simpleType{
		goType: "string",
	}
	Integer Typer = &simpleType{
		goType: "int",
	}
	Double Typer = &simpleType{
		goType: "float64",
	}
	Boolean Typer = &simpleType{
		goType: "bool",
	}
	BinaryType Typer = &simpleType{
		goType: "[]byte",
	}
	Any Typer = &simpleType{
		goType: "interface{}",
	}
	IOReadCloserType Typer = &goType{
		name:       "ReadCloser",
		importPath: "io",
	}
	GetBodyType Typer = &funcType{
		outputs: []Typer{
			IOReadCloserType,
		},
	}
	Bearertoken Typer = &goType{
		name:       "Token",
		importPath: "github.com/palantir/pkg/bearertoken",
	}
	BinaryPkg Typer = &goType{
		name:       "Binary",
		importPath: "github.com/palantir/pkg/binary",
	}
	DateTime Typer = &goType{
		name:       "DateTime",
		importPath: "github.com/palantir/pkg/datetime",
	}
	RID Typer = &goType{
		name:       "ResourceIdentifier",
		importPath: "github.com/palantir/pkg/rid",
	}
	SafeLong Typer = &goType{
		name:       "SafeLong",
		importPath: "github.com/palantir/pkg/safelong",
	}
	UUID Typer = &goType{
		name:       "UUID",
		importPath: "github.com/palantir/pkg/uuid",
	}
	BooleanPkg Typer = &goType{
		name:       "Boolean",
		importPath: "github.com/palantir/pkg/boolean",
	}

	Context Typer = &goType{
		name:       "Context",
		importPath: "context",
	}

	ParseBool Typer = &goType{
		name:       "ParseBool",
		importPath: "strconv",
	}
	ParseFloat Typer = &goType{
		name:       "ParseFloat",
		importPath: "strconv",
	}
	ParseInt Typer = &goType{
		name:       "Atoi",
		importPath: "strconv",
	}
	ParseDateTime Typer = &goType{
		name:       "ParseDateTime",
		importPath: "github.com/palantir/pkg/datetime",
	}
	ParseRID Typer = &goType{
		name:       "ParseRID",
		importPath: "github.com/palantir/pkg/rid",
	}
	ParseSafeLong Typer = &goType{
		name:       "ParseSafeLong",
		importPath: "github.com/palantir/pkg/safelong",
	}
	ParseUUID Typer = &goType{
		name:       "ParseUUID",
		importPath: "github.com/palantir/pkg/uuid",
	}

	Base64Encoding Typer = &goType{
		name:       "StdEncoding",
		importPath: "encoding/base64",
	}
	CodecBinary Typer = &goType{
		name:       "Binary",
		importPath: "github.com/palantir/conjure-go-runtime/v2/conjure-go-contract/codecs",
	}
	CodecJSON Typer = &goType{
		name:       "JSON",
		importPath: "github.com/palantir/conjure-go-runtime/v2/conjure-go-contract/codecs",
	}
	SafeJSONMarshal Typer = &goType{
		name:       "Marshal",
		importPath: "github.com/palantir/pkg/safejson",
	}
	SafeJSONUnmarshal Typer = &goType{
		name:       "Unmarshal",
		importPath: "github.com/palantir/pkg/safejson",
	}
)

func NewGoType

func NewGoType(name, importPath string) Typer

func NewGoTypeFromExternalType

func NewGoTypeFromExternalType(externalType spec.ExternalReference) (Typer, error)

func NewListType

func NewListType(valType Typer) Typer

func NewMapType

func NewMapType(keyType, valType Typer) Typer

func NewOptionalType

func NewOptionalType(valType Typer) Typer

func NewSetType

func NewSetType(valType Typer) Typer

NewSetType creates a new Typer for a set type.

TODO: currently, sets and lists are treated identically. If we want to be more semantically precise, then the proper approach would be to define a Set as a map type with the provided key type and an empty struct as the value type. Because Go doesn't support generics, this would require generating a different Set type ("IntSet", "TestTypeSet", etc.) for each different set type that is required. This type would also need to implement custom JSON serialization and deserialization to translate to a JSON list, since that's the underlying representation required by the spec.

Jump to

Keyboard shortcuts

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