package
0.2.0
Repository: https://github.com/zoumo/golib.git
Documentation: pkg.go.dev

# README

Register

register is a package for golang to build your own register

Example

package main

import "github.com/zoumo/golib/registry"

var (
	clouds = registry.New(nil)
)

type Cloud interface{
	// some interface func
}

type Config struct {
	// some config field
}

type CloudFactory func(Config) (Cloud, error)


func RegisterCloud(name string, factory CloudFactory) {
	clouds.RegisterCloud(cloud, factory)
}

func GetCloud(name string, config Config) (Cloud,error) {
	v, found := clouds.Get(name)
	if !found {
		return nil, nil
	}
	factory := v.(CloudFactory)
	return factory(config)
}

func main() {
	RegisterCloud("aws", AwsCloudFactory)
	RegisterCloud("gce", GceCloudFactory)
	RegisterCloud("azure", AzureCloudFactory)
}

# Functions

New returns a new registry.

# Structs

Config is a struct containing all config for registry.

# Interfaces

Registry provides a place binding name and interface{}.