All Projects → reugn → go-traits

reugn / go-traits

Licence: MIT license
A concept package that helps implement mixin behavior using embedded structs and hook interfaces.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-traits

Mixin
Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
Stars: ✭ 557 (+2552.38%)
Mutual labels:  mixins, trait
mixomatic
Create mixins which work with instanceof (friendly for unit tests).
Stars: ✭ 21 (+0%)
Mutual labels:  mixins, mixin
Uniflow Polymer
UniFlow for Polymer
Stars: ✭ 168 (+700%)
Mutual labels:  mixins
tale-pug
Tale Pug is the popular JavaScript Template Engine Pug, formerly Jade, for PHP!
Stars: ✭ 32 (+52.38%)
Mutual labels:  mixins
austral
Systems language with linear types and capability-based security.
Stars: ✭ 592 (+2719.05%)
Mutual labels:  capabilities
Web Portfolio
Personal portfolio website made with the React
Stars: ✭ 207 (+885.71%)
Mutual labels:  mixins
Solid
.NET apps done SOLID way
Stars: ✭ 18 (-14.29%)
Mutual labels:  composition
Elena Lang
ELENA is a general-purpose language with late binding. It is multi-paradigm, combining features of functional and object-oriented programming. Rich set of tools are provided to deal with message dispatching : multi-methods, message qualifying, generic message handlers, run-time interfaces
Stars: ✭ 161 (+666.67%)
Mutual labels:  mixins
GpuZen2
Sample code for the article 'Real-Time Layered Materials Compositing Using Spatial Clustering Encoding'
Stars: ✭ 17 (-19.05%)
Mutual labels:  composition
Glasstron
The go-to solution to Electron composition effects, such as blurry windows.
Stars: ✭ 243 (+1057.14%)
Mutual labels:  composition
ignite
A Mixin and Access Widener mod loader for Spigot/Paper
Stars: ✭ 115 (+447.62%)
Mutual labels:  mixins
Sponge
The SpongeAPI implementation targeting vanilla Minecraft and 3rd party platforms.
Stars: ✭ 241 (+1047.62%)
Mutual labels:  mixins
Styled Components Spacing
Responsive margin and padding components for styled-components 💅.
Stars: ✭ 209 (+895.24%)
Mutual labels:  mixins
kudojs
A utility library to write code in functional programming style in Javascript
Stars: ✭ 22 (+4.76%)
Mutual labels:  composition
Browser Hack Sass Mixins
Browser hack sass mixin - Apply your SCSS to a specific browser - CSS hacks for: IE, Chrome, Firefox, Edge, Opera
Stars: ✭ 170 (+709.52%)
Mutual labels:  mixins
Grimoire-legacy
General-purpose Mixin loader framework, which allows to properly implement mixins on 1.7.10/1.12.2 versions of Minecraft. For updated version check out https://github.com/Aizistral-Studios/Grimoire
Stars: ✭ 27 (+28.57%)
Mutual labels:  mixins
Sassessentials
Repository for my tutorial course: Sass Essential Training on LinkedIn Learning and Lynda.com.
Stars: ✭ 167 (+695.24%)
Mutual labels:  mixins
Hyperium
Hyperium, Free Minecraft client with HUDs and Popular mods
Stars: ✭ 217 (+933.33%)
Mutual labels:  mixins
functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (+47.62%)
Mutual labels:  composition
NCop
Composite-aspect oriented framework for .NET
Stars: ✭ 30 (+42.86%)
Mutual labels:  mixins

go-traits

Test PkgGoDev Go Report Card

go-traits is a concept package that helps implement mixin behavior using embedded structs and hook interfaces.

Trait list:

  • traits.Hasher - An extension for unique hash generators.
  • traits.Converter - An extension for miscellaneous converters.
  • traits.Stringer - fmt.Stringer implementation extension.
  • traits.Validator - Struct fields validation extension.
  • traits.Default - Struct fields initialization extension.

Marker trait list:

  • traits.PreventUnkeyed - A struct to embed when you need to forbid unkeyed literals usage.
  • traits.NonComparable - A struct to embed when you need to prevent structs comparison.

Hook interfaces:

  • traits.bootstrap - the Bootstrap function will be triggered on traits.Init call.
  • traits.schedule - implement traits.schedule to schedule a function in a separate goroutine on traits.Init call.
  • traits.finalize - the Finalize function will be set as an object finalizer via runtime.SetFinalizer on traits.Init call.

Examples

type inner struct {
	Arr []bool
}

type test struct {
	traits.Hasher
	traits.Converter
	traits.Stringer
	traits.Validator

	Num   int    `json:"num"`
	Str   string `json:"str" valid:"numeric"`
	Inn   *inner
	pstr  *string
	C     chan interface{} `json:"-"`
	Iface interface{}
}

func (t *test) Bootstrap() {
	fmt.Println("Bootstrap Test struct...")
}

func (t *test) Finalize() {
	fmt.Println("Finalize Test struct...")
}

func main() {
	str := "bar"
	obj := test{
		Num:   1,
		Str:   "abc",
		Inn:   &inner{make([]bool, 2)},
		pstr:  &str,
		C:     make(chan interface{}),
		Iface: "foo",
	}
	traits.Init(&obj)

	fmt.Println(obj.String())
	fmt.Println(obj.ToJSON())
	fmt.Println(obj.Md5Hex())
	fmt.Println(obj.Sha256Hex())
	fmt.Println(obj.HashCode32())
	fmt.Println(obj.Validate())
}

See the examples folder for more.

Contributing

Any proposal or improvement is very welcome.

License

Licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].