From a7b87c939fcce8fee2f82c985aa786dcd0587a8d Mon Sep 17 00:00:00 2001 From: Deng Ming Date: Tue, 21 May 2024 22:47:49 +0800 Subject: [PATCH] =?UTF-8?q?spi=20=E4=B8=AD=E6=8E=A5=E5=8F=A3=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spi/doc.go | 18 ++++++++++++++++++ spi/spi.go | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 spi/doc.go create mode 100644 spi/spi.go diff --git a/spi/doc.go b/spi/doc.go new file mode 100644 index 0000000..793a054 --- /dev/null +++ b/spi/doc.go @@ -0,0 +1,18 @@ +// Copyright 2021 ecodeclub +// +// Licensed 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 spi 是指 Service Provider Interface +package spi + + diff --git a/spi/spi.go b/spi/spi.go new file mode 100644 index 0000000..c24307b --- /dev/null +++ b/spi/spi.go @@ -0,0 +1,25 @@ +// Copyright 2021 ecodeclub +// +// Licensed 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 spi + +// LoadService 加载 dir 下面的所有的实现了 T 接口的类型 +// 举个例子来说,如果你有一个叫做 UserService 的接口 +// 而后你将所有的实现都放到了 /ext/user_service 目录下 +// 并且所有的实现,虽然在不同的包,但是都叫做 UserService +// 那么我可以执行 LoadService("/ext/user_service", "UserService") +// 加载到所有的实现 +func LoadService[T any](dir string, symName string) ([]T, error) { + panic("implement me") +}