goexportdefault

command
v0.0.0-...-d7d4131 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2018 License: MIT Imports: 7 Imported by: 0

README

goexportdefault

It is a common pattern in Go packages to implement a default instance of an exported struct and export functions that call the underlying default instance.

A couple of examples from the stdlib:

  • net/http has http.DefaultClient and functions like http.Get just call the default http.DefaultClient.Get
  • log has log.Logger and functions like log.Print just call the default log.std.Print

The exported package functions simply call the corresponding methods from the default instance.

goexportdefault allows you to automatically generate a exported function for each method from a default struct.

Usage

Given the following code:

var DefaultClient = New()
//go:generate goexportdefault DefaultClient

type Client struct {}

func New() *Client {
  return &Client{}
}

// Do won't really do anything in this example
func (c *Client) Do(interface{}) error {
  return nil
}

The it will automatically generate a default_client_funcs.go file with the following contents:

// Do is a wrapper around DefaultClient.Do
func Do(v interface{}) error {
  return DefaultClient.Do(v)
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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