Skip to content

ChrisRx/ifacegen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ifacegen

ifacegen is a code generation tool that generates interfaces from structs.

Usage

A go generate comment can be added to the struct:

package client

import (
	"context"
	"net/url"
)

//go:generate go run github.com/ChrisRx/ifacegen
type Client struct {
    ...
}


// ExportedMethod is an example method for Client that is exported.
func (c *Client) ExportedMethod(ctx context.Context, u *url.URL) (string, error) {
    ...
}

func (c *Client) unExportedMethod() error {
    ...
}

and a file will be produced in the same package named zz_Client.iface.go containing the generated interface:

// Code generated by ifacegen. DO NOT EDIT.

package client

import (
	"context"
	"net/url"
)

type Interface interface {
	// ExportedMethod is an example method for Client that is exported.
	ExportedMethod(ctx context.Context, u *url.URL) (string, error)
}

ifacegen will determine the target struct based upon where in the code the go generate comment is placed.

Flags can be used specify the target struct (--struct-name) or the generated interface name (--iface):

//go:generate go run github.com/ChrisRx/ifacegen --struct-name client -iface Client

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages