Giter VIP home page Giter VIP logo

impast's Introduction

Build Status Maintainability Test Coverage

library for package AST importing.

Installation

go get -u github.com/orisano/impast

How to use

package main

import (
	"fmt"
	"log"
	
	"github.com/orisano/impast"
)

func main() {
	pkg, err := impast.ImportPackage("io")
	if err != nil {
		log.Fatal(err)
	}
	it := impast.FindInterface(pkg, "Writer")
	if it == nil {
		log.Fatalf("io.Writer not found")
	}

	methods := impast.GetRequires(it)
	for _, method := range methods {
		fmt.Println(method.Names[0].Name)
	}
	// Output:
	// Write
}

Useful commands

interfacer

struct to interface command

Installation

go get -u github.com/orisano/impast/cmd/interfacer

How to use

$ interfacer -out HTTPClient net/http.Client
type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
	Get(url string) (resp *http.Response, err error)
	Head(url string) (resp *http.Response, err error)
	Post(url, contentType string, body io.Reader) (resp *http.Response, err error)
	PostForm(url string, data url.Values) (resp *http.Response, err error)
}

mocker

generate mock command

Installation

go get -u github.com/orisano/impast/cmd/mocker

How to use

$ mocker -pkg io -type ReadWriter
type ReadWriterMock struct {
	ReadMock	func(p []byte) (n int, err error)
	WriteMock	func(p []byte) (n int, err error)
}

func (m *ReadWriterMock) Read(p []byte) (n int, err error) {
	return m.ReadMock(p)
}

func (m *ReadWriterMock) Write(p []byte) (n int, err error) {
	return m.WriteMock(p)
}

stuber

generate stub command

Installation

go get -u github.com/orisano/impast/cmd/stuber

How to use

$ stuber -pkg net -implement Conn -export -name c -type "*MyConn"
func (c *MyConn) Read(b []byte) (n int, err error) {
	panic("implement me")
}

func (c *MyConn) Write(b []byte) (n int, err error) {
	panic("implement me")
}

func (c *MyConn) Close() error {
	panic("implement me")
}

func (c *MyConn) LocalAddr() net.Addr {
	panic("implement me")
}

func (c *MyConn) RemoteAddr() net.Addr {
	panic("implement me")
}

func (c *MyConn) SetDeadline(t time.Time) error {
	panic("implement me")
}

func (c *MyConn) SetReadDeadline(t time.Time) error {
	panic("implement me")
}

func (c *MyConn) SetWriteDeadline(t time.Time) error {
	panic("implement me")
}

License

MIT

Author

Nao YONASHIRO (@orisano)

impast's People

Contributors

orisano avatar rt33 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.