GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - lumochift/optgen: functional option generator

BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
generator
generator
 
 
testfile
testfile
 
 
.gitignore
.gitignore
 
 
.goreleaser.yml
.goreleaser.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
main.go
main.go
 
 

Repository files navigation

optgen

GoDoc Build Status codecov Go Report Card

Optional function generator from struct.

Limitation

  • Flag -w currently cannot update generated code, only append code

Installation

go install github.com/lumochift/optgen@latest

Usage

  • Help function
Usage of ./optgen:
  -all
        generate all fields
  -file string
        path file
  -name string
        struct name
  -tag string
        custom tag (default "opt")
  -w    enable write mode
  • Generate file with default tags opt
//thing.go
package foo

type Thing struct {
    Field1 string `opt` 
    Field2 []*int  `opt`
    Field3 map[byte]float64
}

For example we have thing.go and need to generate functional option for struct Thing, only field with opt will generated:

optgen -file thing.go -name Thing

Output:

// NewThing returns a *Thing.
func NewThing(opt ...func(*Thing)) *Thing {

        // Prepare a Thing 
        thing := &Thing{}

        // Apply options.
        for _, o := range opt {
                o(thing)
        }

        // Do anything here

        return thing
}


// SetField1 sets the Field1
func SetField1(field1 string) func(*Thing) {
        return func(c *Thing) {
                c.Field1 = field1
        }
}

// SetField2 sets the Field2
func SetField2(field2 []*int) func(*Thing) {
        return func(c *Thing) {
                c.Field2 = field2
        }
}

About

functional option generator

Topics

generatorgolang

Resources

Readme
MIT license
Activity
Custom properties

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.