Skip to content

Commit

Permalink
add licenses and fix go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu-mi-shan committed Jun 21, 2024
1 parent 6ebc231 commit 411a7cc
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 158 deletions.
14 changes: 14 additions & 0 deletions etcd/client/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 client

import (
Expand Down
14 changes: 14 additions & 0 deletions etcd/client/decoder.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 client

import (
Expand Down
18 changes: 16 additions & 2 deletions etcd/client/loader.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 client

import (
"fmt"
kitexclient "github.com/cloudwego/kitex/client"
"github.com/cloudwego/kitex/pkg/klog"
)

type Translator func(config *EtcdConfig) ([]kitexclient.Option, error)
Expand Down Expand Up @@ -34,7 +48,7 @@ func (l *EtcdLoader) Load() error {
for _, translator := range l.translators {
opts, err := translator(config)
if err != nil {
klog.Errorf(err.Error())
fmt.Println(err)
continue
}
l.options = append(l.options, opts...)
Expand Down
18 changes: 16 additions & 2 deletions etcd/client/reader.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 client

import (
"bytes"
"context"
"github.com/cloudwego/kitex/pkg/klog"
"fmt"
ecli "go.etcd.io/etcd/client/v3"
"text/template"
"time"
Expand Down Expand Up @@ -52,7 +66,7 @@ func (r *EtcdReader) ReadToConfig(p *Path) error {
defer cancel()
data, err := r.etcdClient.Get(ctx2, key)
if err != nil {
klog.Debugf("[etcd] key: %s config get value failed", key)
fmt.Printf("[etcd] key: %s config get value failed", key)
return err
}
err = r.parser.Decode(data.Kvs[0].Value, r.config)
Expand Down
14 changes: 14 additions & 0 deletions etcd/client/suite.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 client

import (
Expand Down
14 changes: 14 additions & 0 deletions etcd/client/translator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 client

import (
Expand Down
14 changes: 14 additions & 0 deletions etcd/server/decoder.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 server

import (
Expand Down
18 changes: 16 additions & 2 deletions etcd/server/loader.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 server

import (
"github.com/cloudwego/kitex/pkg/klog"
"fmt"
kitexserver "github.com/cloudwego/kitex/server"
)

Expand Down Expand Up @@ -33,7 +47,7 @@ func (l *EtcdLoader) Load() error {
for _, translator := range l.translators {
opts, err := translator(config)
if err != nil {
klog.Errorf(err.Error())
fmt.Println(err)
continue
}
l.options = append(l.options, opts...)
Expand Down
18 changes: 16 additions & 2 deletions etcd/server/reader.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 server

import (
"bytes"
"context"
"github.com/cloudwego/kitex/pkg/klog"
"fmt"
ecli "go.etcd.io/etcd/client/v3"
"text/template"
"time"
Expand Down Expand Up @@ -51,7 +65,7 @@ func (r *EtcdReader) ReadToConfig(p *Path) error {
defer cancel()
data, err := r.etcdClient.Get(ctx2, key)
if err != nil {
klog.Debugf("[etcd] key: %s config get value failed", key)
fmt.Printf("[etcd] key: %s config get value failed", key)
return err
}
err = r.parser.Decode(data.Kvs[0].Value, r.config)
Expand Down
14 changes: 14 additions & 0 deletions etcd/server/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 server

import (
Expand Down
14 changes: 14 additions & 0 deletions etcd/server/suite.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 server

import (
Expand Down
14 changes: 14 additions & 0 deletions etcd/server/translator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 server

import (
Expand Down
52 changes: 18 additions & 34 deletions examples/etcd/client/main.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
// Copyright 2024 CloudWeGo Authors
//
// 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 main

import (
"context"
"encoding/json"
"fmt"
kitexclient "github.com/cloudwego/kitex/client"
etcdClient "github.com/kitex-contrib/optionloader/etcd/client"
"github.com/kitex-contrib/optionloader/utils"
examplegen "github.com/zhu-mi-shan/optionloader_example/kitex_gen/example"
example "github.com/zhu-mi-shan/optionloader_example/kitex_gen/example/testservice"
"log"
)

// TestServiceImpl implements the last service interface defined in the IDL.
type TestServiceImpl struct{}

// Test implements the TestServiceImpl interface.
func (s *TestServiceImpl) Test(ctx context.Context, req *examplegen.Req) (resp *examplegen.Resp, err error) {
// TODO: Your code here...
resp = &examplegen.Resp{
Code: "200",
Msg: "ok",
}

return
}

const (
serverServiceName = "echo_server_service"
clientServiceName = "echo_client_service"
Expand Down Expand Up @@ -81,34 +77,22 @@ func main() {
reader, err := etcdClient.NewReader(readerOptions)
//reader, err := etcdClient.NewReader(etcdClient.ReaderOptions{})//使用默认值时的
if err != nil {
log.Fatal(err)
fmt.Println(err)
return
}
myTranslators := []etcdClient.Translator{myTranslator}
loader, err := etcdClient.NewLoader(clientServiceName, serverServiceName, reader, myTranslators...)
if err != nil {
log.Fatal(err)
fmt.Println(err)
return
}
err = loader.Load()
if err != nil {
log.Fatal(err)
fmt.Println(err)
return
}
fmt.Println("Options: ", loader.GetSuite().Options())
config, _ := reader.GetConfig()
fmt.Print("Config:", config.String())
c, err := example.NewClient("echo_server_service", kitexclient.WithSuite(loader.GetSuite()))
if err != nil {
log.Fatal(err)
}
req := examplegen.Req{
Id: 123,
}
resp, err := c.Test(context.Background(), &req)
if err != nil {
log.Fatal(err)
return
}
fmt.Println(resp)
fmt.Println("client.WithSuite():", loader.GetSuite())
}
Loading

0 comments on commit 411a7cc

Please sign in to comment.