github.com/erda-project/erda-infra@v1.0.9/providers/etcd/examples/main.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 main 16 17 import ( 18 "fmt" 19 "os" 20 21 "github.com/coreos/etcd/clientv3" 22 "github.com/erda-project/erda-infra/base/servicehub" 23 "github.com/erda-project/erda-infra/providers/etcd" 24 ) 25 26 type provider struct { 27 ETCD etcd.Interface // autowired 28 Client *clientv3.Client // autowired 29 } 30 31 func (p *provider) Init(ctx servicehub.Context) error { 32 fmt.Println(p.ETCD) 33 fmt.Println(p.Client) 34 return nil 35 } 36 37 func init() { 38 servicehub.Register("example", &servicehub.Spec{ 39 Services: []string{"example"}, 40 Dependencies: []string{"etcd"}, 41 Description: "example", 42 Creator: func() servicehub.Provider { 43 return &provider{} 44 }, 45 }) 46 } 47 48 func main() { 49 hub := servicehub.New() 50 hub.Run("examples", "", os.Args...) 51 } 52 53 // OUTPUT: 54 // INFO[2021-03-18 16:26:31.145] provider etcd initialized 55 // &{0xc00007eaf0 0xc00000ff40 0xc0002029c0 0xc0002cc180} 56 // &{0xc0002def60 0xc0002def90 0xc0002dac80 0xc00007f400 0xc0002df080 0xc0002df0b0 0xc0002ac700 {[https://127.0.0.1:2379] 0 10000000000 0 0 0 0 0xc0002cc180 false [] <nil> <nil> false} 0xc0002f91e0 0xc0002e6660 0xc000039b60 0xc00007b3c0 0x10e6070 <nil> [{false} {2097152} {2147483647}] 0xc0002e6600} 57 // INFO[2021-03-18 16:26:31.145] provider example (depends [etcd]) initialized 58 // INFO[2021-03-18 16:26:31.145] signals to quit:[hangup interrupt terminated quit]