github.com/erda-project/erda-infra@v1.0.9/base/servicehub/examples/unit-test/provider.go (about)

     1  // Copyright (c) 2021 Terminus, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package example
    16  
    17  import (
    18  	"github.com/erda-project/erda-infra/base/servicehub"
    19  )
    20  
    21  // Interface .
    22  type Interface interface {
    23  	Hello(name string) string
    24  	Add(a, b int) int
    25  }
    26  
    27  var _ Interface = (*provider)(nil) // check interface implemented
    28  
    29  type provider struct{}
    30  
    31  func (p *provider) Hello(name string) string {
    32  	return "hello " + name
    33  }
    34  
    35  func (p *provider) Add(a, b int) int {
    36  	return a + b
    37  }
    38  
    39  func (p *provider) sub(a, b int) int {
    40  	return a - b
    41  }
    42  
    43  func init() {
    44  	servicehub.Register("example-provider", &servicehub.Spec{
    45  		Services:    []string{"example"},
    46  		Description: "example",
    47  		Creator: func() servicehub.Provider {
    48  			return &provider{}
    49  		},
    50  	})
    51  }