gen-atomicwrapper

command
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

gen-atomicwrapper generates wrapper types around other atomic types.

It supports plugging in functions which convert the value inside the atomic type to the user-facing value. For example,

Given, atomic.Value and the functions,

func packString(string) interface{}
func unpackString(interface{}) string

We can run the following command:

gen-atomicwrapper -name String -wrapped Value \
  -type string -pack fromString -unpack tostring

This wil generate approximately,

type String struct{ v Value }

func (s *String) Load() string {
  return unpackString(v.Load())
}

func (s *String) Store(s string) {
  return s.v.Store(packString(s))
}

The packing/unpacking logic allows the stored value to be different from the user-facing value.

Without -pack and -unpack, the output will be cast to the target type, defaulting to the zero value.

Jump to

Keyboard shortcuts

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