Git Product home page Git Product logo

go-struct-to-struct's Introduction

go-struct-to-struct

IntelliJ plugin that Automatically generate two struct transformations through function declarations

Usage

  • define func
func transform(d *data.SiteResult) *site.SiteResult {

}

or 

func (s *SiteInfo) transform() *SiteResult {

}
  • Use right click -> Generate (or shortcut key 【Command + N】 for Mac)

  • then. gen code
func transform(d *data.SiteResult) *site.SiteResult {
	return &site.SiteResult{
		SiteAddr:         d.SiteAddr,
		TaskId:           d.TaskId,
		Url:              d.Url,
		Status:           d.Status,
		ResourceType:     d.ResourceType,
		Method:           d.Method,
		RequestBody:      d.RequestBody,
		RequestHeader:    d.RequestHeader,
		ResponseBody:     d.ResponseBody,
		ResponseHeader:   d.ResponseHeader,
		TenantId:         d.TenantId,
		IsTargetDocument: d.IsTargetDocument,
		FailedReason:     d.FailedReason,
		ParentUrl:        d.ParentUrl,
		ParentScreenshot: d.ParentScreenshot,
		DataSource:       d.DataSource,
		Tags:             d.Tags,
	}
}

Reference

https://stackoverflow.com/questions/28294413/how-to-programmatically-use-intellij-idea-code-formatter

https://stackoverflow.com/questions/76561470/how-to-get-gostructtype-object-by-gofunctiondeclaration-idea-plugin-for-goland/76574114#76574114

go-struct-to-struct's People

Contributors

imgbot[bot] avatar yangyang5214 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dbaymax

go-struct-to-struct's Issues

不支持结构体转换?

package foo

type Foo struct {
	Age int64
	Bar Bar
}

type Bar struct {
	Name string
}
type Foo struct {
	Age int64
	Bar Bar
}

type Bar struct {
	Name string
}

func (b *Bar) transform() *foo.Bar {
	return &foo.Bar{
		Name: b.Name,
	}
}

func (f *Foo) transform() *foo.Foo {
	return &foo.Foo{
		Age: f.Age,
		//Bar: f.Bar, // 不能这样转换
	}
}

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.