x

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 2 Imported by: 8

README

x Extension golang module placeholder

Motivation

This project serves as an extension placeholder for a Go module, facilitating an initial setup before dynamic loading of extensions via the Go plugin system.

Consider a scenario where a main application requires extension through custom Go types, which are dynamically reloadable. Suppose the extension module is hosted at github.com/myorg/myapp/extension. This module defines several types and registers them with the Type Registry

The main application, located at github.com/myorg/myapp, needs to access these types both through the Go plugin system for runtime extension and directly as a dependency for compile-time integration. This project is designed to support the direct dependency mechanism, ensuring seamless access to the extension types within the main application's ecosystem.

[Main Application] -> [Transient Extension Module] -> [Extension Module (github.com/myorg/myapp/extension)]

Main Application

The main application go mod.

module github.com/myorg/myapp

go 1.21
  require (
    github.com/viant/x v0.2.0
    github.com/viant/x/transient v0.0.0-00000000000000-000000000000
    github.com/viant/pgo v0.11.0
    ...
  )
    
replace github.com/viant/x => ../../myorg/myapp/x
Transinet Extension Module

The local transient extension go.mod

module github.com/viant/x/transient

go 1.21

require github.com/myorg/myapp/extension

The local transient extension init.go

import _ "github.com/myorg/myapp/extension"
Custom Extension Module

The local transient extension go.mod

module github.com/myorg/myapp/extension

go 1.21

require ...
Extension Module

The extension module registry.go

package mypkg

import (
	"github.com/viant/x"
)

var registry = x.NewRegistry(x.WithListener(func(t *x.Type) {
	// do something with the type
}))

//Register registers a type with options
func Register(t *x.Type) {
	registry.Register(t)
}

//Registry returns extension registry
func Registry() *x.Registry {
	return registry
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SimpleType

func SimpleType(typ reflect.Type) reflect.Type

SimpleType returns a simple type, it unwraps pointer, slice, array, and chan

Types

type Listener

type Listener func(t *Type)

Listener represents a listener

type MergeListener added in v0.3.0

type MergeListener func() Listener

MergeListener represents a merge listener

type Option

type Option func(t *Type)

Option represent type option

func WithForceFlag

func WithForceFlag() Option

WithForceFlag will force the type to be generated

func WithName

func WithName(name string) Option

WithName is an option to set the name of the type

func WithPkgPath added in v0.3.0

func WithPkgPath(pkg string) Option

WithPkgPath is an option to set the package path of the type

func WithScn

func WithScn(at int) Option

WithScn is an option to set the scn(sequence change number) of the type

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry represents an extension type

func NewRegistry

func NewRegistry(options ...RegistryOption) *Registry

NewRegistry creates a registry

func (*Registry) Lookup

func (r *Registry) Lookup(name string) *Type

Lookup returns a type by name

func (*Registry) Merge

func (r *Registry) Merge(registry *Registry)

Merge merges registry

func (*Registry) Register

func (r *Registry) Register(aType *Type)

Register registers a type

func (*Registry) Scn

func (r *Registry) Scn() int

Scn returns registry sequence change number

type RegistryOption

type RegistryOption func(r *Registry)

RegistryOption represent registry option

func WithListener

func WithListener(listener Listener) RegistryOption

WithListener creates a new registry with the specified listener

func WithMergeListener added in v0.3.0

func WithMergeListener(listener MergeListener) RegistryOption

WithMergeListener creates a new registry with the specified listener

func WithRegistryScn

func WithRegistryScn(scn int) RegistryOption

WithRegistryScn is an option to set scn time

type Type

type Type struct {
	Type       reflect.Type
	PkgPath    string
	Location   string
	Name       string
	Definition string
	Scn        int
	Force      bool
	// contains filtered or unexported fields
}

Type represents a type

func NewType

func NewType(t reflect.Type, options ...Option) *Type

NewType creates a type

func (*Type) IsNamed

func (t *Type) IsNamed() bool

IsNamed returns true if type is named

func (*Type) Key

func (t *Type) Key() string

Directories

Path Synopsis
extension module
transient module

Jump to

Keyboard shortcuts

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