Version: v0.0.0-...-886b66b Latest Latest

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

Go to latest
Published: Jul 21, 2022 License: Apache-2.0 Imports: 3 Imported by: 0



Package gostring contains the implementation of the gostring plugin, which generates the deriveGoString function.

The deriveGoString function returns a string that reproduces the argument's value in valid go syntax. The deriveGoString function does a recursive print, even printing pointer values, unlike the default %#v operand.

When goderive walks over your code it is looking for a function that:

  • was not implemented (or was previously derived) and
  • has a predefined prefix.

In the following code the deriveGoString function will be found, because it was not implemented and it has a prefix deriveGoString. This prefix is configurable.

package main

type MyStruct struct {
	Int64     int64
	StringPtr *string

func (this *MyStruct) GoString() string {
	return deriveGoString(this)

func main () {
	s := "abc"
	fmt.Printf("%#v", &MyStruct{StringPtr: &s})

The %#v fmt operand will then invoke the GoString method. GoString does a recursive print, even printing pointer values, unlike the default %#v operand.

Supported types:

  • basic types
  • named structs
  • slices
  • maps
  • pointers to these types
  • and many more

Unsupported types:

  • chan
  • interface
  • function
  • private fields
  • unnamed structs

Example output can be found here: https://github.com/awalterschulze/goderive/tree/master/example/plugin/gostring

This plugin has been tested thoroughly.



This section is empty.


This section is empty.


func New

New is a constructor for the gostring code generator. This generator should be reconstructed for each package.

func NewPlugin

func NewPlugin() derive.Plugin

NewPlugin creates a new gostring plugin. This function returns the plugin name, default prefix and a constructor for the gostring code generator.


This section is empty.

Source Files

Jump to

Keyboard shortcuts

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