EvanLjp commented on a change in pull request #5: URL: https://github.com/apache/skywalking-satellite/pull/5#discussion_r532207523
########## File path: internal/satellite/registry/registry.go ########## @@ -0,0 +1,168 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package registry + +import ( + "fmt" + + "github.com/apache/skywalking-satellite/internal/pkg/api" +) + +// The creator reg. +type pluginRegistry struct { + collectorCreatorRegistry map[string]CollectorCreator + queueCreatorRegistry map[string]QueueCreator + filterCreatorRegistry map[string]FilterCreator + forwarderCreatorRegistry map[string]ForwarderCreator + parserCreatorRegistry map[string]ParserCreator + clientCreatorRegistry map[string]ClientCreator +} + +// ClientCreator creates a Client according to the config. +type ClientCreator func(config map[string]interface{}) (api.Collector, error) + +// CollectorCreator creates a Collector according to the config. +type CollectorCreator func(config map[string]interface{}) (api.Collector, error) + +// QueueCreator creates a Queue according to the config. +type QueueCreator func(config map[string]interface{}) (api.Queue, error) + +// FilterCreator creates a Filter according to the config. +type FilterCreator func(config map[string]interface{}) (api.Filter, error) + +// ForwarderCreator creates a forwarder according to the config. +type ForwarderCreator func(config map[string]interface{}) (api.Forwarder, error) + +// ParserCreator creates a parser according to the config. +type ParserCreator func(config map[string]interface{}) (api.Parser, error) + +var reg *pluginRegistry + +// RegisterClient registers the clientType as ClientCreator. +func RegisterClient(clientType string, creator ClientCreator) { + fmt.Printf("register client creator success : %s", clientType) Review comment: the creator is a func to create a new instance, its name is stored in a map. I think that is enough to use. In the future code, I would implement plugins in ./plugins dir. The plugin type would be as the next level dirs, such as collector, client, or queue. And the 3rd level would be the plugin name. Maybe I would like to implement a method to read the parent dir as the plugin name. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org