profile

package
v3.10.13 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 39 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package profile is for specific profiles @todo this package is the definition of cruft and should be rewritten in a more elegant way

Index

Constants

This section is empty.

Variables

View Source
var Client = &Profile{
	Name:  "client",
	Setup: func(ctx *cli.Context) error { return nil },
}

Client profile is for any entrypoint that behaves as a client

View Source
var Dev = &Profile{
	Name: "dev",
	Setup: func(ctx *cli.Context) error {
		auth.DefaultAuth = mAuthNoop.NewAuth()
		runtime.DefaultRuntime = mRuntimeLocal.NewRuntime()

		store.DefaultStore = mStoreNoop.NewStore()
		config.DefaultConfig, _ = mConfigEnv.NewConfig()
		var err error
		events.DefaultStream, err = mEventStream.NewStream()
		if err != nil {
			logger.Fatalf("Error configuring stream for simple profile: %v", err)
		}

		SetupBroker(mBrokerMemory.NewBroker())

		setupRegistry(mRegistryNoop.NewRegistry())

		return nil
	},
}

Dev profile to run service in simple config

View Source
var Kubernetes = &Profile{
	Name: "kubernetes",
	Setup: func(ctx *cli.Context) (err error) {
		auth.DefaultAuth = mAuthJwt.NewAuth()
		SetupJWT(ctx)

		runtime.DefaultRuntime = mRuntimeK8s.NewRuntime()
		build.DefaultBuilder, err = mBuildGolang.NewBuilder()
		if err != nil {
			logger.Fatalf("Error configuring golang builder: %v", err)
		}

		events.DefaultStream, err = mEventStream.NewStream()
		if err != nil {
			logger.Fatalf("Error configuring stream: %v", err)
		}

		store.DefaultStore = mStoreFile.NewStore(mStoreFile.WithDir("/store"))
		store.DefaultBlobStore, err = mStoreFile.NewBlobStore(mStoreFile.WithDir("/store/blob"))
		if err != nil {
			logger.Fatalf("Error configuring file blob store: %v", err)
		}

		model.DefaultModel = model.NewModel(
			model.WithStore(store.DefaultStore),
		)

		if ctx.Args().Get(1) == "registry" {
			SetupRegistry(mRegMemory.NewRegistry())
		}

		if ctx.Args().Get(1) == "broker" {
			SetupBroker(mBrokerMemory.NewBroker())
		}

		config.DefaultConfig, err = mConfigStore.NewConfig(store.DefaultStore, "")
		if err != nil {
			logger.Fatalf("Error configuring config: %v", err)
		}
		SetupConfigSecretKey(ctx)

		router.DefaultRouter = mRouterK8s.NewRouter()
		client.DefaultClient.Init(client.Router(router.DefaultRouter))

		tracingServiceName := ctx.Args().Get(1)
		if len(tracingServiceName) == 0 {
			tracingServiceName = "Micro"
		}
		openTracer, _, err := jaeger.New(
			opentelemetry.WithServiceName(tracingServiceName),
			opentelemetry.WithTraceReporterAddress("localhost:6831"),
		)
		if err != nil {
			logger.Fatalf("Error configuring opentracing: %v", err)
		}
		opentelemetry.DefaultOpenTracer = openTracer

		return nil
	},
}

Kubernetes profile to run on kubernetes with zero deps. Designed for use with the micro helm chart

View Source
var Local = &Profile{
	Name: "local",
	Setup: func(ctx *cli.Context) error {
		auth.DefaultAuth = mAuthJwt.NewAuth()
		store.DefaultStore = mStoreFile.NewStore(mStoreFile.WithDir(filepath.Join(inUser.Dir, "server", "store")))
		SetupConfigSecretKey(ctx)
		config.DefaultConfig, _ = mConfigStore.NewConfig(store.DefaultStore, "")

		SetupJWT(ctx)

		if ctx.Args().Get(1) == "registry" {
			SetupRegistry(mRegMemory.NewRegistry())
		} else {

			registry.DefaultRegistry.Init(
				registry.Addrs("localhost:8000"),
			)

			SetupRegistry(registry.DefaultRegistry)
		}

		if ctx.Args().Get(1) == "broker" {
			SetupBroker(mBrokerMemory.NewBroker())
		} else {
			broker.DefaultBroker.Init(
				broker.Addrs("localhost:8003"),
			)
			SetupBroker(broker.DefaultBroker)
		}

		model.DefaultModel = model.NewModel(
			model.WithStore(store.DefaultStore),
		)

		runtime.DefaultRuntime = mRuntimeLocal.NewRuntime()

		var err error
		events.DefaultStream, err = mEventStream.NewStream()
		if err != nil {
			logger.Fatalf("Error configuring stream: %v", err)
		}
		events.DefaultStore = mEventStore.NewStore(
			mEventStore.WithStore(store.DefaultStore),
		)

		store.DefaultBlobStore, err = mStoreFile.NewBlobStore()
		if err != nil {
			logger.Fatalf("Error configuring file blob store: %v", err)
		}

		tracingServiceName := ctx.Args().Get(1)
		if len(tracingServiceName) == 0 {
			tracingServiceName = "Micro"
		}
		openTracer, _, err := jaeger.New(
			opentelemetry.WithServiceName(tracingServiceName),
			opentelemetry.WithSamplingRate(1),
		)
		if err != nil {
			logger.Fatalf("Error configuring opentracing: %v", err)
		}
		opentelemetry.DefaultOpenTracer = openTracer

		return nil
	},
}

Local profile to run locally

View Source
var Service = &Profile{
	Name:  "service",
	Setup: func(ctx *cli.Context) error { return nil },
}

Service is the default for any services run

View Source
var Simple = &Profile{
	Name: "simple",
	Setup: func(ctx *cli.Context) error {
		auth.DefaultAuth = mAuthNoop.NewAuth()
		runtime.DefaultRuntime = mRuntimeLocal.NewRuntime()

		store.DefaultStore = mStoreMemory.NewStore()
		config.DefaultConfig, _ = mConfigEnv.NewConfig()
		var err error
		events.DefaultStream, err = mEventStream.NewStream()
		if err != nil {
			logger.Fatalf("Error configuring stream for simple profile: %v", err)
		}

		SetupBroker(mBrokerMemory.NewBroker())

		setupRegistry(mRegistryNoop.NewRegistry())

		return nil
	},
}

Simple profile to run service in simple config

View Source
var Test = &Profile{
	Name: "test",
	Setup: func(ctx *cli.Context) error {
		auth.DefaultAuth = mAuthNoop.NewAuth()
		store.DefaultStore = mStoreMemory.NewStore()
		store.DefaultBlobStore, _ = mStoreFile.NewBlobStore()
		config.DefaultConfig, _ = mConfigStore.NewConfig(store.DefaultStore, "")
		SetupRegistry(mRegMemory.NewRegistry())

		model.DefaultModel = model.NewModel(
			model.WithStore(store.DefaultStore),
		)
		return nil
	},
}

Test profile is used for the go test suite

Functions

func Register

func Register(name string, p *Profile) error

Register a profile

func SetupBroker

func SetupBroker(b broker.Broker)

SetupBroker configures the broker

func SetupConfigSecretKey

func SetupConfigSecretKey(ctx *cli.Context)

SetupConfigSecretKey config default SecretKey

func SetupJWT

func SetupJWT(ctx *cli.Context)

SetupJWT configures the default internal system rules

func SetupRegistry

func SetupRegistry(reg registry.Registry)

SetupRegistry configures the registry

Types

type Profile

type Profile struct {
	// name of the profile
	Name string
	// function used for setup
	Setup func(*cli.Context) error
}

Profile configures an environment

func Load

func Load(name string) (*Profile, error)

Load a profile

Jump to

Keyboard shortcuts

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