Giter Site home page Giter Site logo

svgen's Introduction

svgen Build Status

svgen search for the constants of types which are the aliases for int or string types, i.e.:

package db

type RideStatus string

const(
  RideStatusStarted   RideStatus = "started"
  RideStatusComplete  RideStatus = "completed"
)

Using found types and constants it generates sql.Scanner and driver.Valuer implementations for these types:

/*
DO NOT EDIT! This code was generated automatically using github.com/gojuno/svgen v1.0
*/
package db

import (
	"database/sql/driver"
	"fmt"
)

func (t *RideStatus) Scan(i interface{}) error {
	var vv RideStatus
	switch v := i.(type) {
	case nil:
		return nil
	case []byte:
		vv = RideStatus(v)
	case string:
		vv = RideStatus(v)
	default:
		return fmt.Errorf("can't scan %T into %T", v, t)
	}

	switch vv {
	case RideStatusInitiated:
	case RideStatusComplete:
	default:
		return fmt.Errorf("invalid value of type RideStatus: %v", vv)
	}

	*t = vv

	return nil
}

func (t RideStatus) Value() (driver.Value, error) {
	if t == "" {
		return nil, nil
	}
	switch t {
	case RideStatusInitiated:
	case RideStatusComplete:
	default:
		return nil, fmt.Errorf("invalid value of type RideStatus: %v", t)
	}

	return string(t), nil
}

Supported command line flags:

  -i string
    	import path of the package containing type declarations
  -o string
    	output file name (default "scanners_valuers.go")

Usage of svgen in go:generate instruction:

//go:generate svgen -i your.package/name -o scanners_valuers_generated.go

Run tests

make

svgen's People

Contributors

hexdigest avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.