Like tools/cmd/stringer with bitmask features

Bitmasker GoDoc

Bitmasker is a tool used to automate the creation of helper methods when dealing with bitmask-type constant flags. Given the name of an unsigned integer type T that has constants defined, bitmasker will create a new self-contained Go source file implementing the BitMask and fmt.Stringer interfaces.

Getting Started

To get up and running, follow the normal go install procedure:

go install github.com/go-curses/bitmasker

Example Usage

Bitmasker is intended to be used with go:generate but can operated standalone as well. For example:

Given this snippet:

package mental

//go:generate bitmasker -type=State
type State uint

const (
    Unconscious State = 0
    Conscious State = (1 << iota)
    Meditative
    Distracted
    Entertained = Distracted
)

Standalone usage:

bitmasker -type=State

Using go-generate

go generate

In both cases a new file named "state_bitmask.go" will be created with the following contents:

// Code generated by "bitmasker -type=State"; DO NOT EDIT.

package mental

import "strconv"

func (i State) Has(m State) bool {
	return i&m != 0
}

func (i State) Set(m State) State {
	return i | m
}

func (i State) Clear(m State) State {
	return i &^ m
}

func (i State) Toggle(m State) State {
	return i ^ m
}

const (
	_State_name_0 = "Unconscious"
	_State_name_1 = "Conscious"
	_State_name_2 = "Meditative"
	_State_name_3 = "Distracted"
)

func (i State) String() string {
	switch {
	case i == 0:
		return _State_name_0
	case i == 2:
		return _State_name_1
	case i == 4:
		return _State_name_2
	case i == 8:
		return _State_name_3
	default:
		return "State(" + strconv.FormatInt(int64(i), 10) + ")"
	}
}

Running the tests

Unit tests are provided and can be invoked using the normal Go pattern:

go test

Authors

  • Kevin C. Krinke - Bitmasker author - kckrinke
  • The Go Authors - Stringer derived sources - stringer

License

This project is licensed under the LGPL (specifically v3) - see the LICENSE.md file for details.

Acknowledgments

  • Thanks to Golang.org for the stringer program that bitmasker sources are derived from.
Owner
Go Curses
GTK inspired API for terminal user interfaces.
Go Curses
Similar Resources

Little Bug Bounty & Hacking Tools⚔️

Little Bug Bounty & Hacking Tools ⚔️

Jan 7, 2023

common tools for golang

utils common tools for golang package main

Dec 27, 2021

Source code of Liteloader Tools

LiteLoader Tools This repository store the source code of some LiteLoader Tools Prebuilt Binary see /bin folder Image2Binary [Golang] convert Image(jp

Aug 30, 2022

Go tools sourcecode read and customize

Go Tools This subrepository holds the source for various packages and tools that support the Go programming language. Some of the tools, godoc and vet

Oct 24, 2021

Mackerel SLI/SLO tools

shimesaba For SRE to operate and monitor services using Mackerel. Description shimesaba is a tool for tracking SLO/ErrorBudget using Mackerel as an SL

Nov 21, 2022

Functional tools in Go 1.18 using newly introduced generics

functools functools is a simple Go library that brings you your favourite functi

Dec 5, 2022

Generic-based collection tools

go-collection go collection is a tool implemented using generic, it can help you process slice/map data quickly and easily convert between them. Note:

Dec 29, 2022

Golang source code parsing, usage like reflect package

gotype Golang source code parsing, usage like reflect package English 简体中文 Usage API Documentation Examples License Pouch is licensed under the MIT Li

Dec 9, 2022

A super simple Lodash like utility library with essential functions that empowers the development in Go

A super simple Lodash like utility library with essential functions that empowers the development in Go

A simple Utility library for Go Go does not provide many essential built in functions when it comes to the data structure such as slice and map. This

Jan 4, 2023
This project contains an example that showcases different features from the official Go Client for Elasticsearch
This project contains an example that showcases different features from the official Go Client for Elasticsearch

Elasticsearch for Gophers This project contains an example that showcases different features from the official Go Client for Elasticsearch that you ca

Oct 12, 2022
Yet another StructTag, with some features liked cache and alias.

Yet another StructTag, with some features liked cache and alias.

Nov 1, 2021
A set of instrumentation features for collecting relevant tracing data as well as secure an application

Go Agent goagent provides a set of instrumentation features for collecting relevant tracing data as well as secure an application by blocking requests

Dec 21, 2021
xgen generator with extend features

XGen Plus Generator Introduction xgen is a library written in pure Go providing a set of functions that allow you to parse XSD (XML schema definition)

Dec 8, 2021
A rule-based tunnel in Go with experimental features.
 A rule-based tunnel in Go with experimental features.

This repository is for archiving only Experimental-Clash A rule-based tunnel in Go with experimental features. Features Local HTTP/HTTPS/SOCKS server

Dec 3, 2021
A library that provides Go Generics friendly "optional" features.

go-optional A library that provides Go Generics friendly "optional" features. Synopsis some := optional.Some[int](123) fmt.Printf("%v\n", some.IsSome(

Dec 20, 2022
Code generation tools for Go.

interfaces Code generation tools for Go's interfaces. Tools available in this repository: cmd/interfacer cmd/structer cmd/interfacer Generates an inte

Dec 23, 2022
A directory of hardware related libs, tools, and tutorials for Go

Go + hardware This repo is a directory of tools, packages and tutorials to let you introduce Go in your hardware projects. Why Go? Go can target platf

Dec 30, 2022
gqlanalysis makes easy to develop static analysis tools for GraphQL in Go.
gqlanalysis makes easy to develop static analysis tools for GraphQL in Go.

gqlanalysis gqlanalysis defines the interface between a modular static analysis for GraphQL in Go. gqlanalysis is inspired by go/analysis. gqlanalysis

Dec 14, 2022
gopkg is a universal utility collection for Go, it complements offerings such as Boost, Better std, Cloud tools.

gopkg is a universal utility collection for Go, it complements offerings such as Boost, Better std, Cloud tools. Table of Contents Introduction

Jan 5, 2023