🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/jimtwn/stringer

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/jimtwn/stringer

v0.0.0-20241104181752-8bc5f5ede8fa
Source
Go
Version published
Created
Source

stringer

This program is a drop-in replacement for Go's commonly used stringer tool. In addition to generating String() string implementations for individual constants, this version also works with bit flag sets.

For instance:

    type T uint

    const (
        Foo T = 1 << iota
        Bar
        Baz
    )

When invoking Foo.String(), we should get "Foo". When invoking (Foo|Bar).String() the old stringer tool will only print a numeric value: "T(3)". In our case, we will get the expected: "Foo, Bar". Unknown values in a bit flag set will still be presented in the "T(3)" form:

    (T(1<<12) | Baz).String() == "Baz, T(4096)"

Usage

$ go get -u github.com/hexaflex/stringer

In the go source file, use a go:generate statement to have the tool generate the required code. This tool recognizes all the existing options Go's stringer recognizes.

//go:generate stringer -type=MyType

In order to treat a type as a bit flag set, use:

//go:generate stringer -flags -type=MyType

License

Copyright 2014 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

FAQs

Package last updated on 04 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts