cmtstringer

command module
v0.0.0-...-8db431e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

README

cmtstringer - Comment to String

Build Status GoDoc

cmtstringer is a tool that help to generate method func (t T) String() string, which satisfy the fmt.Stringer interface, for given type name of a constant. Returned value is the comment text of the constant.

Install

To install command cmtstringer, run command

go get github.com/lazada/cmtstringer

Usage

For example, given this file

package http

//go:generate cmtstringer -type StatusCode

type StatusCode int

const (
    // StatusBadRequest Bad Request
    StatusBadRequest StatusCode = 400
    // StatusNotFound Not Found
    StatusNotFound StatusCode = 404
)

run command

go generate

then you will get file statuscode_string_gen.go

package http

// This file is generated by command cmtstringer.
// DO NOT EDIT IT.

// String returns comment of const type StatusCode
func (s StatusCode) String() string {
    switch s {
    case StatusBadRequest:
        return "Bad Request"
    case StatusNotFound:
        return "Not Found"
    default:
        return "Unknown"
    }
}

License

Licensed under the Apache License, Version 2.0 (the "License").

Documentation

Overview

Command cmtstringer is a tool that help to generate method `func (t T) String() string`, which satisfy the fmt.Stringer interface, for given type name of a constant. Returned value is the comment text of the constant.

Install

To install command cmtstringer, run command

go get github.com/lazada/cmtstringer

Usage

For example, given this file

package http

//go:generate cmtstringer -type StatusCode

type StatusCode int

const (
	// StatusBadRequest Bad Request
	StatusBadRequest StatusCode = 400
	// StatusNotFound Not Found
	StatusNotFound StatusCode = 404
)

run command

go generate

then you will get file `statuscode_string_gen.go`

package http

// This file is generated by command cmtstringer.
// DO NOT EDIT IT.

// String returns comment of const type StatusCode
func (s StatusCode) String() string {
	switch s {
	case StatusBadRequest:
		return "Bad Request"
	case StatusNotFound:
		return "Not Found"
	default:
		return "Unknown"
	}
}

Directories

Path Synopsis
Package http is used for testing purpose only
Package http is used for testing purpose only

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL