當前位置: 首頁>>代碼示例>>Golang>>正文


Golang id.MustNewID函數代碼示例

本文整理匯總了Golang中github.com/xh3b4sd/anna/service/id.MustNewID函數的典型用法代碼示例。如果您正苦於以下問題:Golang MustNewID函數的具體用法?Golang MustNewID怎麽用?Golang MustNewID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MustNewID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewStorage

// NewStorage creates a new configured redis storage object.
func NewStorage(config StorageConfig) (spec.Storage, error) {
	newStorage := &storage{
		StorageConfig: config,

		ID:           id.MustNewID(),
		ShutdownOnce: sync.Once{},
		Type:         ObjectType,
	}

	// Dependencies.
	if newStorage.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newStorage.Pool == nil {
		return nil, maskAnyf(invalidConfigError, "connection pool must not be empty")
	}
	// Settings.
	if newStorage.BackoffFactory == nil {
		return nil, maskAnyf(invalidConfigError, "backoff factory must not be empty")
	}
	if newStorage.Prefix == "" {
		return nil, maskAnyf(invalidConfigError, "prefix must not be empty")
	}

	newStorage.Log.Register(newStorage.GetType())

	return newStorage, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:29,代碼來源:storage.go

示例2: New

// New creates a new configured feature set object. A feature set tries to
// detect all patterns within the configured input sequences.
func New(config Config) (spec.FeatureSet, error) {
	newFeatureSet := &featureSet{
		Config: config,
		ID:     id.MustNewID(),
		Mutex:  sync.Mutex{},
		Type:   ObjectTypeFeatureSet,
	}

	if newFeatureSet.MaxLength < -1 {
		return nil, maskAnyf(invalidConfigError, "MaxLength must be greater than -2")
	}
	if newFeatureSet.MinLength < 1 {
		return nil, maskAnyf(invalidConfigError, "MaxLength must be greater than 0")
	}
	if newFeatureSet.MaxLength != -1 && newFeatureSet.MaxLength < newFeatureSet.MinLength {
		return nil, maskAnyf(invalidConfigError, "MaxLength must be equal to or greater thanMinLength")
	}
	if newFeatureSet.MinCount < 0 {
		return nil, maskAnyf(invalidConfigError, "MinCount must be greater than -1")
	}
	if len(newFeatureSet.Sequences) == 0 {
		return nil, maskAnyf(invalidConfigError, "sequences must not be empty")
	}

	return newFeatureSet, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:28,代碼來源:feature_set.go

示例3: New

// New creates a new configured annad object.
func New(config Config) (spec.Annad, error) {
	newAnna := &annad{
		Config: config,

		BootOnce:     sync.Once{},
		ID:           id.MustNewID(),
		ShutdownOnce: sync.Once{},
		Type:         ObjectType,
	}

	if newAnna.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newAnna.Network == nil {
		return nil, maskAnyf(invalidConfigError, "network must not be empty")
	}
	if newAnna.Server == nil {
		return nil, maskAnyf(invalidConfigError, "server must not be empty")
	}
	if newAnna.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "service collection must not be empty")
	}
	if newAnna.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}

	return newAnna, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:29,代碼來源:main.go

示例4: New

// New creates a new configured forwarder object.
func New(config Config) (systemspec.Forwarder, error) {
	newForwarder := &forwarder{
		Config: config,

		ID:   id.MustNewID(),
		Type: ObjectType,
	}

	// Dependencies.
	if newForwarder.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "factory collection must not be empty")
	}
	if newForwarder.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newForwarder.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}

	// Settings.
	if newForwarder.MaxSignals == 0 {
		return nil, maskAnyf(invalidConfigError, "maximum signals must not be empty")
	}

	newForwarder.Log.Register(newForwarder.GetType())

	return newForwarder, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:29,代碼來源:forwarder.go

示例5: New

// New creates a new configured network object.
func New(config Config) (systemspec.Network, error) {
	newNetwork := &network{
		Config: config,

		BootOnce:     sync.Once{},
		Closer:       make(chan struct{}, 1),
		ID:           id.MustNewID(),
		ShutdownOnce: sync.Once{},
		Type:         ObjectType,
	}

	if newNetwork.Activator == nil {
		return nil, maskAnyf(invalidConfigError, "activator must not be empty")
	}
	if newNetwork.Forwarder == nil {
		return nil, maskAnyf(invalidConfigError, "forwarder must not be empty")
	}
	if newNetwork.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newNetwork.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "service collection must not be empty")
	}
	if newNetwork.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}
	if newNetwork.Tracker == nil {
		return nil, maskAnyf(invalidConfigError, "tracker must not be empty")
	}

	newNetwork.CLGs = newNetwork.newCLGs()
	newNetwork.Log.Register(newNetwork.GetType())

	return newNetwork, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:36,代碼來源:network.go

示例6: NewDistribution

// NewDistribution creates a new configured distribution object. A distribution
// represents a weighted analysis of vectors. A two dimensional distribution
// can be seen as bar chart.
//
//     ^
//     |         x
//     |         x
//     |         x    x
//   y |         x    x
//     |         x    x
//     |    x    x    x
//     |    x    x    x    x
//     |    x    x    x    x
//     +------------------------>
//                 x
//
func NewDistribution(config Config) (spec.Distribution, error) {
	newDistribution := &distribution{
		Config: config,
		ID:     id.MustNewID(),
		Mutex:  sync.Mutex{},
		Type:   ObjectTypeDistribution,
	}

	if newDistribution.Name == "" {
		return nil, maskAnyf(invalidConfigError, "name must not be empty")
	}
	if len(newDistribution.Vectors) == 0 {
		return nil, maskAnyf(invalidConfigError, "vectors must not be empty")
	}
	if !equalDimensionLength(newDistribution.Vectors) {
		return nil, maskAnyf(invalidConfigError, "vectors must have equal dimensions")
	}
	if len(newDistribution.StaticChannels) == 0 {
		return nil, maskAnyf(invalidConfigError, "vectors must not be empty")
	}
	if !uniqueFloat64(newDistribution.StaticChannels) {
		return nil, maskAnyf(invalidConfigError, "static channels must be unique")
	}

	sort.Float64s(newDistribution.StaticChannels)

	return newDistribution, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:44,代碼來源:distribution.go

示例7: NewFeature

// NewFeature creates a new configured feature object. A feature represents a
// differentiable part of a given sequence.
func NewFeature(config FeatureConfig) (spec.Feature, error) {
	newFeature := &feature{
		Distribution:  nil,
		FeatureConfig: config,
		ID:            id.MustNewID(),
		Mutex:         sync.Mutex{},
		Type:          ObjectTypeFeature,
	}

	if len(newFeature.Positions) == 0 {
		return nil, maskAnyf(invalidConfigError, "positions must not be empty")
	}
	if newFeature.Sequence == "" {
		return nil, maskAnyf(invalidConfigError, "sequence must not be empty")
	}

	newConfig := distribution.DefaultConfig()
	newConfig.Name = newFeature.Sequence
	newConfig.Vectors = newFeature.Positions
	newDistribution, err := distribution.NewDistribution(newConfig)
	if err != nil {
		return nil, maskAnyf(invalidConfigError, err.Error())
	}
	newFeature.Distribution = newDistribution

	return newFeature, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:29,代碼來源:feature.go

示例8: DefaultConfig

// DefaultConfig provides a default configuration to create a new command line
// object by best effort.
func DefaultConfig() Config {
	newLogControl, err := logcontrol.NewControl(logcontrol.DefaultControlConfig())
	if err != nil {
		panic(err)
	}

	newTextInterface, err := text.NewClient(text.DefaultClientConfig())
	if err != nil {
		panic(err)
	}

	newConfig := Config{
		// Dependencies.
		Log:               log.New(log.DefaultConfig()),
		LogControl:        newLogControl,
		ServiceCollection: service.MustNewCollection(),
		TextInterface:     newTextInterface,

		// Settings.
		Flags:     Flags{},
		SessionID: string(id.MustNewID()),
		Version:   version,
	}

	return newConfig
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:28,代碼來源:main.go

示例9: New

// New creates a new configured network payload object.
func New(config Config) (spec.NetworkPayload, error) {
	newObject := &networkPayload{
		Config: config,

		ID: id.MustNewID(),
	}

	return newObject, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:10,代碼來源:networkpayload.go

示例10: NewFileSystem

// NewFileSystem creates a new configured real OS file system.
func NewFileSystem(config Config) servicespec.FS {
	newFileSystem := &osFileSystem{
		Config: config,
		ID:     id.MustNewID(),
		Mutex:  sync.Mutex{},
		Type:   ObjectType,
	}

	newFileSystem.Log.Register(newFileSystem.GetType())

	return newFileSystem
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:13,代碼來源:os.go

示例11: New

// New creates a new configured context object.
func New(config Config) (spec.Context, error) {
	newContext := &context{
		Config: config,

		ID: string(id.MustNewID()),
	}

	if newContext.Context == nil {
		return nil, maskAnyf(invalidConfigError, "context must not be empty")
	}

	return newContext, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:14,代碼來源:context.go

示例12: New

// New creates a new configured CLG collection object.
func New(config Config) (systemspec.CLGCollection, error) {
	newCollection := &collection{
		Config: config,

		ID:    id.MustNewID(),
		Mutex: sync.Mutex{},
		Type:  ObjectTypeCLGCollection,
	}

	newCollection.Log.Register(newCollection.GetType())

	return newCollection, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:14,代碼來源:collection.go

示例13: New

// New creates a new configured log object.
func New(config Config) spec.Log {
	newLog := log{
		Config: config,

		ID:                id.MustNewID(),
		Mutex:             sync.Mutex{},
		RegisteredObjects: []spec.ObjectType{},
		Type:              ObjectType,
	}

	newLog.Register(newLog.GetType())

	return &newLog
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:15,代碼來源:log.go

示例14: New

// New creates a new configured memory file system.
func New(config Config) (servicespec.FS, error) {
	newService := &service{
		Config:  config,
		ID:      id.MustNewID(),
		Mutex:   sync.Mutex{},
		Storage: map[string][]byte{},
		Type:    ObjectType,
	}

	if newService.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}

	return newService, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:16,代碼來源:mem.go

示例15: NewControl

// NewControl creates a new configured log control object.
func NewControl(config ControlConfig) (spec.LogControl, error) {
	newControl := &control{
		ControlConfig: config,
		ID:            id.MustNewID(),
		Mutex:         sync.Mutex{},
		Type:          ObjectType,
	}

	if newControl.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}

	newControl.Log.Register(newControl.GetType())

	return newControl, nil
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:17,代碼來源:control.go


注:本文中的github.com/xh3b4sd/anna/service/id.MustNewID函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。