You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "ywxzm03 (via GitHub)" <gi...@apache.org> on 2026/05/14 06:59:01 UTC
[PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
ywxzm03 opened a new pull request, #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148
**What this PR does**:
Completes the `https` Pixiu sample as a runnable and verifiable HTTPS -> Pixiu -> Dubbo provider -> Zookeeper chain.
Aligned with the expected behavior described in the issue, this PR:
- Aligns the cluster referenced by `conf.yaml` routes with the cluster defined in `conf.yaml`:
- Uses `test_dubbo` for both `route.cluster` and `clusters[].name`.
- Aligns the Dubbo integration `clusterName` in `api_config.yaml` with the Pixiu cluster config:
- Keeps `clusterName` as `test_dubbo`.
- Makes it match the Pixiu cluster defined in `conf.yaml`.
- Builds a clear main path across the HTTPS listener, API resource path, Dubbo integration, and Zookeeper registry:
- Updates the API path to `/api/v1/test-dubbo/:interface` (aligned with the new http->dubbo configuration style in `dubbo-go-pixiu`: the legacy `opt.application` mapping has been removed from Dubbo sample options; `dubbogo/simple/proxy` was also migrated to the same path shape in 4374696).
- Switches the HTTPS sample from a static endpoint to Zookeeper-based Dubbo service discovery.
- Adds a Dubbo provider that registers `com.dubbogo.pixiu.UserService`.
- Uses Docker Compose to start Pixiu, the Dubbo provider, Zookeeper, and the local certificate initialization task together.
- Adds a verifiable entry point to prove that HTTPS requests can reach the Dubbo provider:
- Adds an HTTPS request script.
- Adds an integration test.
- Adds an `integrate_test.sh https` path that starts Docker Compose and runs the HTTPS integration test.
**Which issue(s) this PR fixes**:
Fixes #147
**Special notes for your reviewer**:
- This sample runs Pixiu in Docker instead of starting it directly on the host. Pixiu v1.1.0 uses autocert for the HTTPS listener and binds the standard HTTPS port `443`. Since `443` is a privileged port on macOS/Linux, a normal user process cannot reliably bind it in local or CI environments. The sample therefore lets Pixiu listen on `443` inside the container and maps it to host port `8443`.
- This sample also avoids relying on real ACME certificate issuance. ACME/autocert normally requires a publicly reachable domain and external validation, which is not suitable for a local sample. The Compose setup generates a self-signed certificate cache for `sample.domain.com` and mounts it into Pixiu's autocert cache directory. The test client and `request.sh` intentionally use insecure TLS verification for this local sample path.
- The Dubbo provider also runs inside Docker Compose. This keeps Pixiu, the provider, and Zookeeper on the same Docker network, so the provider address registered in Zookeeper is directly reachable by Pixiu. If the provider ran on the host while Pixiu ran in a container, the provider could register a host-local or otherwise unreachable address, causing Pixiu to discover the service but fail to connect.
**Does this PR introduce a user-facing change?**:
```release-note
Complete the HTTPS Pixiu Dubbo sample chain with Dockerized Pixiu, Dubbo provider, Zookeeper registry setup, and integration test.
```
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on code in PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#discussion_r3242072038
##########
https/server/app/user.go:
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the 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.
+ * The 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 main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "sync"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+func init() {
+ dubbo.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+
+ cache = newUserDB()
+
+ t1, _ := time.Parse(
+ time.RFC3339,
+ "2021-08-01T10:08:41+00:00")
+
+ cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: t1})
+ cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: t1})
+}
+
+var cache *userDB
+
+// userDB cache user.
+type userDB struct {
+ // key is name, value is user obj
+ nameIndex map[string]*User
+ // key is code, value is user obj
+ codeIndex map[int64]*User
+ lock sync.Mutex
+}
+
+// userDB create func
+func newUserDB() *userDB {
+ return &userDB{
+ nameIndex: make(map[string]*User, 16),
+ codeIndex: make(map[int64]*User, 16),
+ lock: sync.Mutex{},
+ }
+}
+
+// nolint
+func (db *userDB) Add(u *User) bool {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ if u.Name == "" || u.Code <= 0 {
+ return false
+ }
+
+ if !db.existName(u.Name) && !db.existCode(u.Code) {
+ return db.AddForName(u) && db.AddForCode(u)
+ }
+
+ return false
+}
+
+// nolint
+func (db *userDB) AddForName(u *User) bool {
+ if len(u.Name) == 0 {
+ return false
+ }
+
+ if _, ok := db.nameIndex[u.Name]; ok {
+ return false
+ }
+
+ db.nameIndex[u.Name] = u
+ return true
+}
+
+// nolint
+func (db *userDB) AddForCode(u *User) bool {
+ if u.Code <= 0 {
+ return false
+ }
+
+ if _, ok := db.codeIndex[u.Code]; ok {
+ return false
+ }
+
+ db.codeIndex[u.Code] = u
+ return true
+}
+
+// nolint
+func (db *userDB) GetByName(n string) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.nameIndex[n]
+ return r, ok
+}
+
+// nolint
+func (db *userDB) GetByCode(n int64) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.codeIndex[n]
+ return r, ok
+}
+
+func (db *userDB) existName(name string) bool {
+ if len(name) <= 0 {
+ return false
+ }
+
+ _, ok := db.nameIndex[name]
+ return ok
+}
+
+func (db *userDB) existCode(code int64) bool {
+ if code <= 0 {
+ return false
+ }
+
+ _, ok := db.codeIndex[code]
+ return ok
+}
+
+// User user obj.
+type User struct {
+ ID string `json:"id,omitempty"`
+ Code int64 `json:"code,omitempty"`
+ Name string `json:"name,omitempty"`
+ Age int32 `json:"age,omitempty"`
+ Time time.Time `json:"time,omitempty"`
+}
+
+// UserProvider the dubbo provider.
+// like: version: 1.0.0 group: test
+type UserProvider struct{}
+
+// CreateUser new user, PX config POST.
+func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) {
+ fmt.Printf("Req CreateUser data: %#v \n", user)
Review Comment:
但据我统计,其他示例中的 user.go 都是用的 fmt.Printf 或 outLn(占比最大),我是否该改成 outLn,从而与其他示例对齐,还是改成您说的 logger?
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#discussion_r3241453086
##########
https/server/app/user.go:
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the 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.
+ * The 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 main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "sync"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+func init() {
+ dubbo.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+
+ cache = newUserDB()
+
+ t1, _ := time.Parse(
+ time.RFC3339,
+ "2021-08-01T10:08:41+00:00")
+
+ cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: t1})
+ cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: t1})
+}
+
+var cache *userDB
+
+// userDB cache user.
+type userDB struct {
+ // key is name, value is user obj
+ nameIndex map[string]*User
+ // key is code, value is user obj
+ codeIndex map[int64]*User
+ lock sync.Mutex
+}
+
+// userDB create func
+func newUserDB() *userDB {
+ return &userDB{
+ nameIndex: make(map[string]*User, 16),
+ codeIndex: make(map[int64]*User, 16),
+ lock: sync.Mutex{},
+ }
+}
+
+// nolint
+func (db *userDB) Add(u *User) bool {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ if u.Name == "" || u.Code <= 0 {
+ return false
+ }
+
+ if !db.existName(u.Name) && !db.existCode(u.Code) {
+ return db.AddForName(u) && db.AddForCode(u)
+ }
+
+ return false
+}
+
+// nolint
+func (db *userDB) AddForName(u *User) bool {
+ if len(u.Name) == 0 {
+ return false
+ }
+
+ if _, ok := db.nameIndex[u.Name]; ok {
+ return false
+ }
+
+ db.nameIndex[u.Name] = u
+ return true
+}
+
+// nolint
+func (db *userDB) AddForCode(u *User) bool {
+ if u.Code <= 0 {
+ return false
+ }
+
+ if _, ok := db.codeIndex[u.Code]; ok {
+ return false
+ }
+
+ db.codeIndex[u.Code] = u
+ return true
+}
+
+// nolint
+func (db *userDB) GetByName(n string) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.nameIndex[n]
+ return r, ok
+}
+
+// nolint
+func (db *userDB) GetByCode(n int64) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.codeIndex[n]
+ return r, ok
+}
+
+func (db *userDB) existName(name string) bool {
+ if len(name) <= 0 {
+ return false
+ }
+
+ _, ok := db.nameIndex[name]
+ return ok
+}
+
+func (db *userDB) existCode(code int64) bool {
+ if code <= 0 {
+ return false
+ }
+
+ _, ok := db.codeIndex[code]
+ return ok
+}
+
+// User user obj.
+type User struct {
+ ID string `json:"id,omitempty"`
+ Code int64 `json:"code,omitempty"`
+ Name string `json:"name,omitempty"`
+ Age int32 `json:"age,omitempty"`
+ Time time.Time `json:"time,omitempty"`
+}
+
+// UserProvider the dubbo provider.
+// like: version: 1.0.0 group: test
+type UserProvider struct{}
+
+// CreateUser new user, PX config POST.
+func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) {
+ fmt.Printf("Req CreateUser data: %#v \n", user)
+ if user == nil {
+ return nil, errors.New("not found")
+ }
+ _, ok := cache.GetByName(user.Name)
+ if ok {
+ return nil, errors.New("data is exist")
+ }
+
+ b := cache.Add(user)
+ if b {
+ return user, nil
+ }
+
+ return nil, errors.New("add error")
+}
+
+// GetUserByName query by name, single param, PX config GET.
+func (u *UserProvider) GetUserByName(ctx context.Context, name string) (*User, error) {
+ fmt.Printf("Req GetUserByName name: %#v \n", name)
+ r, ok := cache.GetByName(name)
+ if ok {
+ fmt.Printf("Req GetUserByName result: %#v \n", r)
+ return r, nil
+ }
+ return nil, nil
+}
+
+// GetUserByCode query by code, single param, PX config GET.
+func (u *UserProvider) GetUserByCode(ctx context.Context, code int64) (*User, error) {
+ fmt.Printf("Req GetUserByCode name: %#v \n", code)
+ r, ok := cache.GetByCode(code)
+ if ok {
+ fmt.Printf("Req GetUserByCode result: %#v \n", r)
+ return r, nil
+ }
+ return nil, nil
+}
+
+// GetUserTimeout query by name, will timeout for pixiu.
+func (u *UserProvider) GetUserTimeout(ctx context.Context, name string) (*User, error) {
+ fmt.Printf("Req GetUserByName name: %#v \n", name)
+ // sleep 10s, pixiu config less than 10s.
+ time.Sleep(10 * time.Second)
+ r, ok := cache.GetByName(name)
+ if ok {
+ fmt.Printf("Req GetUserByName result: %#v \n", r)
+ return r, nil
+ }
+ return nil, nil
+}
+
+// GetUserByNameAndAge query by name and age, two params, PX config GET.
+func (u *UserProvider) GetUserByNameAndAge(ctx context.Context, name string, age int32) (*User, error) {
+ fmt.Printf("Req GetUserByNameAndAge name: %s, age: %d \n", name, age)
+ r, ok := cache.GetByName(name)
+ if ok && r.Age == age {
+ fmt.Printf("Req GetUserByNameAndAge result: %#v \n", r)
+ return r, nil
+ }
+ return r, nil
+}
+
+// UpdateUser update by user struct, my be another struct, PX config POST or PUT.
+func (u *UserProvider) UpdateUser(ctx context.Context, user *User) (bool, error) {
+ fmt.Printf("Req UpdateUser data: %#v \n", user)
+ r, ok := cache.GetByName(user.Name)
Review Comment:
[P0] 这里通过 GetByName 拿到 map 中保存的 *User 后,在没有持有 userDB.lock 的情况下直接修改 r.ID/r.Age;同时 GetUserByName/GetUserByCode 可以并发读取同一个对象。RPC handler 是并发执行的,这会产生数据竞争,race detector 会报错,严重时响应内容可能读到半更新状态。建议把更新逻辑封装到 userDB 的加锁方法里,或让 GetByName 返回深拷贝,并用 go test -race 覆盖并发读写。
##########
https/server/app/user.go:
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the 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.
+ * The 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 main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "sync"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+func init() {
+ dubbo.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+
+ cache = newUserDB()
+
+ t1, _ := time.Parse(
+ time.RFC3339,
+ "2021-08-01T10:08:41+00:00")
+
+ cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: t1})
+ cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: t1})
+}
+
+var cache *userDB
+
+// userDB cache user.
+type userDB struct {
+ // key is name, value is user obj
+ nameIndex map[string]*User
+ // key is code, value is user obj
+ codeIndex map[int64]*User
+ lock sync.Mutex
+}
+
+// userDB create func
+func newUserDB() *userDB {
+ return &userDB{
+ nameIndex: make(map[string]*User, 16),
+ codeIndex: make(map[int64]*User, 16),
+ lock: sync.Mutex{},
+ }
+}
+
+// nolint
+func (db *userDB) Add(u *User) bool {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ if u.Name == "" || u.Code <= 0 {
+ return false
+ }
+
+ if !db.existName(u.Name) && !db.existCode(u.Code) {
+ return db.AddForName(u) && db.AddForCode(u)
+ }
+
+ return false
+}
+
+// nolint
+func (db *userDB) AddForName(u *User) bool {
+ if len(u.Name) == 0 {
+ return false
+ }
+
+ if _, ok := db.nameIndex[u.Name]; ok {
+ return false
+ }
+
+ db.nameIndex[u.Name] = u
+ return true
+}
+
+// nolint
+func (db *userDB) AddForCode(u *User) bool {
+ if u.Code <= 0 {
+ return false
+ }
+
+ if _, ok := db.codeIndex[u.Code]; ok {
+ return false
+ }
+
+ db.codeIndex[u.Code] = u
+ return true
+}
+
+// nolint
+func (db *userDB) GetByName(n string) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.nameIndex[n]
+ return r, ok
+}
+
+// nolint
+func (db *userDB) GetByCode(n int64) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.codeIndex[n]
+ return r, ok
+}
+
+func (db *userDB) existName(name string) bool {
+ if len(name) <= 0 {
+ return false
+ }
+
+ _, ok := db.nameIndex[name]
+ return ok
+}
+
+func (db *userDB) existCode(code int64) bool {
+ if code <= 0 {
+ return false
+ }
+
+ _, ok := db.codeIndex[code]
+ return ok
+}
+
+// User user obj.
+type User struct {
+ ID string `json:"id,omitempty"`
+ Code int64 `json:"code,omitempty"`
+ Name string `json:"name,omitempty"`
+ Age int32 `json:"age,omitempty"`
+ Time time.Time `json:"time,omitempty"`
+}
+
+// UserProvider the dubbo provider.
+// like: version: 1.0.0 group: test
+type UserProvider struct{}
+
+// CreateUser new user, PX config POST.
+func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) {
+ fmt.Printf("Req CreateUser data: %#v \n", user)
Review Comment:
[P1] 新增 provider 路径里多处直接使用 fmt.Printf 打请求和结果,和工程日志规范不一致,也绕过了 APP_LOG_CONF_FILE 配置。请改成工程 logger,并把同文件其它 fmt.Printf 一并替换;fmt 只用于格式化时再保留。
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#discussion_r3294011712
##########
https/request.sh:
##########
@@ -0,0 +1,33 @@
+#
+# Licensed to the 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. The 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.
+#
+DOMAIN="sample.domain.com"
+PORT="8443"
+ADDRESS="https://${DOMAIN}:${PORT}"
+RESOLVE="${DOMAIN}:${PORT}:127.0.0.1"
+
+API1=$(curl -k --resolve "${RESOLVE}" -s -X POST "${ADDRESS}/api/v1/test-dubbo/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByName" -d '{"types":"string","values":"tc"}' --header 'Content-Type: application/json')
+API2=$(curl -k --resolve "${RESOLVE}" -s -X POST "${ADDRESS}/api/v1/test-dubbo/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=UpdateUserByName" -d '{"types":"string, object","values":["tc",{"id":"0001","code":1,"name":"tc","age":15}]}' --header "Content-Type: application/json")
+API3=$(curl -k --resolve "${RESOLVE}" -s -X POST "${ADDRESS}/api/v1/test-dubbo/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByCode" -d '{"types":"int","values":1}' --header "Content-Type: application/json")
+
+ARRAY_API=(${API1} ${API2} ${API3})
+
+for element in ${ARRAY_API[@]}
+do
+echo ${element}
Review Comment:
`ARRAY_API=(${API1} ${API2} ${API3})` and the subsequent loop expand variables unquoted, so any spaces/newlines in responses (or in variables) will be word-split and echoed as multiple elements. This makes the script output unreliable. Prefer printing each response directly, or use a properly quoted array/loop (e.g., store each response as an element without word-splitting and iterate with quoted expansions).
##########
https/request.sh:
##########
@@ -0,0 +1,33 @@
+#
+# Licensed to the 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. The 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.
+#
+DOMAIN="sample.domain.com"
+PORT="8443"
+ADDRESS="https://${DOMAIN}:${PORT}"
+RESOLVE="${DOMAIN}:${PORT}:127.0.0.1"
+
+API1=$(curl -k --resolve "${RESOLVE}" -s -X POST "${ADDRESS}/api/v1/test-dubbo/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByName" -d '{"types":"string","values":"tc"}' --header 'Content-Type: application/json')
+API2=$(curl -k --resolve "${RESOLVE}" -s -X POST "${ADDRESS}/api/v1/test-dubbo/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=UpdateUserByName" -d '{"types":"string, object","values":["tc",{"id":"0001","code":1,"name":"tc","age":15}]}' --header "Content-Type: application/json")
+API3=$(curl -k --resolve "${RESOLVE}" -s -X POST "${ADDRESS}/api/v1/test-dubbo/com.dubbogo.pixiu.UserService?group=test&version=1.0.0&method=GetUserByCode" -d '{"types":"int","values":1}' --header "Content-Type: application/json")
Review Comment:
The JSON payload for UpdateUserByName uses `"types":"string, object"` (note the space after the comma). Other samples/tests in this repo use `string,object` without spaces, and the extra whitespace can cause Pixiu/Dubbo type parsing to fail if the implementation does not trim tokens. Align this payload with the format used elsewhere (no spaces) to keep the request script verifiable.
##########
https/test/pixiu_test.go:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the 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.
+ * The 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 test
+
+import (
+ "context"
+ "crypto/tls"
+ "io"
+ "net"
+ "net/http"
+ "strings"
+ "testing"
+ "time"
+)
+
+import (
+ "github.com/stretchr/testify/assert"
+)
+
+const (
+ httpsDomain = "sample.domain.com"
+ httpsPort = "8443"
+ httpsTarget = "127.0.0.1:" + httpsPort
+ httpsAPI = "https://" + httpsDomain + ":" + httpsPort + "/api/v1/test-dubbo/com.dubbogo.pixiu.UserService"
+ waitTimeout = 180 * time.Second
+)
+
+func newHTTPSClient() *http.Client {
+ dialer := &net.Dialer{Timeout: 5 * time.Second}
+ return &http.Client{
+ Timeout: 5 * time.Second,
+ Transport: &http.Transport{
+ DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
+ if addr == httpsDomain+":"+httpsPort {
+ addr = httpsTarget
+ }
+ return dialer.DialContext(ctx, network, addr)
+ },
+ TLSClientConfig: &tls.Config{
+ MinVersion: tls.VersionTLS12,
+ ServerName: httpsDomain,
+ InsecureSkipVerify: true, //nolint:gosec
+ },
+ },
+ }
+}
+
+func post(t *testing.T, url string, data string) string {
+ t.Helper()
+
+ client := newHTTPSClient()
+ deadline := time.Now().Add(waitTimeout)
+ var lastBody string
+ var lastErr error
+ var lastStatus int
+
+ for {
+ req, err := http.NewRequest("POST", url, strings.NewReader(data))
+ assert.NoError(t, err)
+ req.Header.Add("Content-Type", "application/json")
+
+ resp, err := client.Do(req)
+ if err == nil && resp != nil {
+ body, _ := io.ReadAll(resp.Body)
+ _ = resp.Body.Close()
+ lastBody = string(body)
+ lastStatus = resp.StatusCode
+ if resp.StatusCode == http.StatusOK {
+ return lastBody
+ }
+ } else {
+ lastErr = err
Review Comment:
In the retry loop, when `client.Do(req)` returns a non-nil `resp` together with a non-nil `err` (which net/http can do in some cases), the current code goes into the `else` branch and does not close `resp.Body`. This can leak connections and make retries behave poorly. Handle/close `resp.Body` whenever `resp != nil`, even if `err != nil` (and consider capturing status/body for diagnostics in that path too).
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on code in PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#discussion_r3246046972
##########
https/server/app/user.go:
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the 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.
+ * The 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 main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "sync"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+func init() {
+ dubbo.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+
+ cache = newUserDB()
+
+ t1, _ := time.Parse(
+ time.RFC3339,
+ "2021-08-01T10:08:41+00:00")
+
+ cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: t1})
+ cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: t1})
+}
+
+var cache *userDB
+
+// userDB cache user.
+type userDB struct {
+ // key is name, value is user obj
+ nameIndex map[string]*User
+ // key is code, value is user obj
+ codeIndex map[int64]*User
+ lock sync.Mutex
+}
+
+// userDB create func
+func newUserDB() *userDB {
+ return &userDB{
+ nameIndex: make(map[string]*User, 16),
+ codeIndex: make(map[int64]*User, 16),
+ lock: sync.Mutex{},
+ }
+}
+
+// nolint
+func (db *userDB) Add(u *User) bool {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ if u.Name == "" || u.Code <= 0 {
+ return false
+ }
+
+ if !db.existName(u.Name) && !db.existCode(u.Code) {
+ return db.AddForName(u) && db.AddForCode(u)
+ }
+
+ return false
+}
+
+// nolint
+func (db *userDB) AddForName(u *User) bool {
+ if len(u.Name) == 0 {
+ return false
+ }
+
+ if _, ok := db.nameIndex[u.Name]; ok {
+ return false
+ }
+
+ db.nameIndex[u.Name] = u
+ return true
+}
+
+// nolint
+func (db *userDB) AddForCode(u *User) bool {
+ if u.Code <= 0 {
+ return false
+ }
+
+ if _, ok := db.codeIndex[u.Code]; ok {
+ return false
+ }
+
+ db.codeIndex[u.Code] = u
+ return true
+}
+
+// nolint
+func (db *userDB) GetByName(n string) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.nameIndex[n]
+ return r, ok
+}
+
+// nolint
+func (db *userDB) GetByCode(n int64) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.codeIndex[n]
+ return r, ok
+}
+
+func (db *userDB) existName(name string) bool {
+ if len(name) <= 0 {
+ return false
+ }
+
+ _, ok := db.nameIndex[name]
+ return ok
+}
+
+func (db *userDB) existCode(code int64) bool {
+ if code <= 0 {
+ return false
+ }
+
+ _, ok := db.codeIndex[code]
+ return ok
+}
+
+// User user obj.
+type User struct {
+ ID string `json:"id,omitempty"`
+ Code int64 `json:"code,omitempty"`
+ Name string `json:"name,omitempty"`
+ Age int32 `json:"age,omitempty"`
+ Time time.Time `json:"time,omitempty"`
+}
+
+// UserProvider the dubbo provider.
+// like: version: 1.0.0 group: test
+type UserProvider struct{}
+
+// CreateUser new user, PX config POST.
+func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) {
+ fmt.Printf("Req CreateUser data: %#v \n", user)
Review Comment:
好的
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#issuecomment-4527511986
> > 这个示例在集成测试里面吗
>
> 能的
那就加一下
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#discussion_r3246022626
##########
https/server/app/user.go:
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the 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.
+ * The 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 main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "sync"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+func init() {
+ dubbo.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+
+ cache = newUserDB()
+
+ t1, _ := time.Parse(
+ time.RFC3339,
+ "2021-08-01T10:08:41+00:00")
+
+ cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: t1})
+ cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: t1})
+}
+
+var cache *userDB
+
+// userDB cache user.
+type userDB struct {
+ // key is name, value is user obj
+ nameIndex map[string]*User
+ // key is code, value is user obj
+ codeIndex map[int64]*User
+ lock sync.Mutex
+}
+
+// userDB create func
+func newUserDB() *userDB {
+ return &userDB{
+ nameIndex: make(map[string]*User, 16),
+ codeIndex: make(map[int64]*User, 16),
+ lock: sync.Mutex{},
+ }
+}
+
+// nolint
+func (db *userDB) Add(u *User) bool {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ if u.Name == "" || u.Code <= 0 {
+ return false
+ }
+
+ if !db.existName(u.Name) && !db.existCode(u.Code) {
+ return db.AddForName(u) && db.AddForCode(u)
+ }
+
+ return false
+}
+
+// nolint
+func (db *userDB) AddForName(u *User) bool {
+ if len(u.Name) == 0 {
+ return false
+ }
+
+ if _, ok := db.nameIndex[u.Name]; ok {
+ return false
+ }
+
+ db.nameIndex[u.Name] = u
+ return true
+}
+
+// nolint
+func (db *userDB) AddForCode(u *User) bool {
+ if u.Code <= 0 {
+ return false
+ }
+
+ if _, ok := db.codeIndex[u.Code]; ok {
+ return false
+ }
+
+ db.codeIndex[u.Code] = u
+ return true
+}
+
+// nolint
+func (db *userDB) GetByName(n string) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.nameIndex[n]
+ return r, ok
+}
+
+// nolint
+func (db *userDB) GetByCode(n int64) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.codeIndex[n]
+ return r, ok
+}
+
+func (db *userDB) existName(name string) bool {
+ if len(name) <= 0 {
+ return false
+ }
+
+ _, ok := db.nameIndex[name]
+ return ok
+}
+
+func (db *userDB) existCode(code int64) bool {
+ if code <= 0 {
+ return false
+ }
+
+ _, ok := db.codeIndex[code]
+ return ok
+}
+
+// User user obj.
+type User struct {
+ ID string `json:"id,omitempty"`
+ Code int64 `json:"code,omitempty"`
+ Name string `json:"name,omitempty"`
+ Age int32 `json:"age,omitempty"`
+ Time time.Time `json:"time,omitempty"`
+}
+
+// UserProvider the dubbo provider.
+// like: version: 1.0.0 group: test
+type UserProvider struct{}
+
+// CreateUser new user, PX config POST.
+func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) {
+ fmt.Printf("Req CreateUser data: %#v \n", user)
Review Comment:
改成logger吧
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#issuecomment-4527297148
> 这个示例在集成测试里面吗
能的
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#issuecomment-4528222263
merge到最新的main看一下ci运行
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#issuecomment-4451600496
> Read-only review: 发现 1 个 P0、1 个 P1 问题。golangci-lint 未运行,当前环境缺少 golangci-lint;go test ./https/test -run Test -count=1 未完成,测试依赖本地 8443 HTTPS 样例服务,5 分钟超时
这里的 `go test ./https/test` 不是该样例的预期运行入口
`https/test` 是依赖外部样例环境的集成测试,不是可以单独运行的单元测试。它本身不会启动 Pixiu、Dubbo provider、Zookeeper,也不会准备 HTTPS 证书。它只会向 `https://sample.domain.com:8443` 发请求
这个样例需要通过:
`./integrate_test.sh https`
来运行。脚本会先通过 Docker Compose 启动 Pixiu、Dubbo provider、Zookeeper 和证书初始化任务,然后再执行集成测试
直接运行 `go test ./https/test` 会失败/超时,主要是因为必要的样例环境没有被拉起:
- `go test` 不会启动 Pixiu,因此本地 `8443` 上没有 HTTPS 服务可访问
- `go test` 不会启动证书初始化任务,也不会为 Pixiu 准备 `sample.domain.com` 的本地证书缓存
- `go test` 不会启动 Zookeeper 和 Dubbo provider
- 当前 Pixiu 和 provider 配置中的 Zookeeper 地址是 `zookeeper:2181`,这是 Docker Compose 网络里的 service name;如果绕开 Compose、改为宿主机直接启动相关进程,这个地址通常无法解析
这里使用 Docker Compose 是有意设计的,主要原因是:
- Pixiu v1.1.0 的 HTTPS listener 使用 autocert,并会监听标准 HTTPS 端口 `443`;如果直接在宿主机启动 Pixiu,普通用户进程在 macOS/Linux 上无法稳定监听 `443`
- 本地样例不能依赖真实 ACME 证书申请,所以 Compose 中增加了 `pixiu-cert-init`,用于生成 `sample.domain.com` 的本地自签证书缓存
- Pixiu、provider 和 Zookeeper 放在同一个 Docker Compose 网络中,可以保证 provider 注册到 Zookeeper 的地址能被 Pixiu 访问
因此,直接运行 `go test ./https/test` 超时是预期内的,因为必要的样例环境没有启动;正确的验证方式是运行 `./integrate_test.sh https`
如果一定希望 `go test ./https/test` 也能独立触发完整链路,那就需要让测试本身负责拉起和清理 Docker Compose,或者在测试里间接调用 `./integrate_test.sh https`,但似乎会显得有些臃肿
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on code in PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#discussion_r3242199042
##########
https/server/app/user.go:
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the 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.
+ * The 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 main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "sync"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3"
+
+ hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+func init() {
+ dubbo.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+
+ cache = newUserDB()
+
+ t1, _ := time.Parse(
+ time.RFC3339,
+ "2021-08-01T10:08:41+00:00")
+
+ cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: t1})
+ cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: t1})
+}
+
+var cache *userDB
+
+// userDB cache user.
+type userDB struct {
+ // key is name, value is user obj
+ nameIndex map[string]*User
+ // key is code, value is user obj
+ codeIndex map[int64]*User
+ lock sync.Mutex
+}
+
+// userDB create func
+func newUserDB() *userDB {
+ return &userDB{
+ nameIndex: make(map[string]*User, 16),
+ codeIndex: make(map[int64]*User, 16),
+ lock: sync.Mutex{},
+ }
+}
+
+// nolint
+func (db *userDB) Add(u *User) bool {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ if u.Name == "" || u.Code <= 0 {
+ return false
+ }
+
+ if !db.existName(u.Name) && !db.existCode(u.Code) {
+ return db.AddForName(u) && db.AddForCode(u)
+ }
+
+ return false
+}
+
+// nolint
+func (db *userDB) AddForName(u *User) bool {
+ if len(u.Name) == 0 {
+ return false
+ }
+
+ if _, ok := db.nameIndex[u.Name]; ok {
+ return false
+ }
+
+ db.nameIndex[u.Name] = u
+ return true
+}
+
+// nolint
+func (db *userDB) AddForCode(u *User) bool {
+ if u.Code <= 0 {
+ return false
+ }
+
+ if _, ok := db.codeIndex[u.Code]; ok {
+ return false
+ }
+
+ db.codeIndex[u.Code] = u
+ return true
+}
+
+// nolint
+func (db *userDB) GetByName(n string) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.nameIndex[n]
+ return r, ok
+}
+
+// nolint
+func (db *userDB) GetByCode(n int64) (*User, bool) {
+ db.lock.Lock()
+ defer db.lock.Unlock()
+
+ r, ok := db.codeIndex[n]
+ return r, ok
+}
+
+func (db *userDB) existName(name string) bool {
+ if len(name) <= 0 {
+ return false
+ }
+
+ _, ok := db.nameIndex[name]
+ return ok
+}
+
+func (db *userDB) existCode(code int64) bool {
+ if code <= 0 {
+ return false
+ }
+
+ _, ok := db.codeIndex[code]
+ return ok
+}
+
+// User user obj.
+type User struct {
+ ID string `json:"id,omitempty"`
+ Code int64 `json:"code,omitempty"`
+ Name string `json:"name,omitempty"`
+ Age int32 `json:"age,omitempty"`
+ Time time.Time `json:"time,omitempty"`
+}
+
+// UserProvider the dubbo provider.
+// like: version: 1.0.0 group: test
+type UserProvider struct{}
+
+// CreateUser new user, PX config POST.
+func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) {
+ fmt.Printf("Req CreateUser data: %#v \n", user)
+ if user == nil {
+ return nil, errors.New("not found")
+ }
+ _, ok := cache.GetByName(user.Name)
+ if ok {
+ return nil, errors.New("data is exist")
+ }
+
+ b := cache.Add(user)
+ if b {
+ return user, nil
+ }
+
+ return nil, errors.New("add error")
+}
+
+// GetUserByName query by name, single param, PX config GET.
+func (u *UserProvider) GetUserByName(ctx context.Context, name string) (*User, error) {
+ fmt.Printf("Req GetUserByName name: %#v \n", name)
+ r, ok := cache.GetByName(name)
+ if ok {
+ fmt.Printf("Req GetUserByName result: %#v \n", r)
+ return r, nil
+ }
+ return nil, nil
+}
+
+// GetUserByCode query by code, single param, PX config GET.
+func (u *UserProvider) GetUserByCode(ctx context.Context, code int64) (*User, error) {
+ fmt.Printf("Req GetUserByCode name: %#v \n", code)
+ r, ok := cache.GetByCode(code)
+ if ok {
+ fmt.Printf("Req GetUserByCode result: %#v \n", r)
+ return r, nil
+ }
+ return nil, nil
+}
+
+// GetUserTimeout query by name, will timeout for pixiu.
+func (u *UserProvider) GetUserTimeout(ctx context.Context, name string) (*User, error) {
+ fmt.Printf("Req GetUserByName name: %#v \n", name)
+ // sleep 10s, pixiu config less than 10s.
+ time.Sleep(10 * time.Second)
+ r, ok := cache.GetByName(name)
+ if ok {
+ fmt.Printf("Req GetUserByName result: %#v \n", r)
+ return r, nil
+ }
+ return nil, nil
+}
+
+// GetUserByNameAndAge query by name and age, two params, PX config GET.
+func (u *UserProvider) GetUserByNameAndAge(ctx context.Context, name string, age int32) (*User, error) {
+ fmt.Printf("Req GetUserByNameAndAge name: %s, age: %d \n", name, age)
+ r, ok := cache.GetByName(name)
+ if ok && r.Age == age {
+ fmt.Printf("Req GetUserByNameAndAge result: %#v \n", r)
+ return r, nil
+ }
+ return r, nil
+}
+
+// UpdateUser update by user struct, my be another struct, PX config POST or PUT.
+func (u *UserProvider) UpdateUser(ctx context.Context, user *User) (bool, error) {
+ fmt.Printf("Req UpdateUser data: %#v \n", user)
+ r, ok := cache.GetByName(user.Name)
Review Comment:
收到
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#issuecomment-4527295098
> #147
能的
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: complete and align HTTPS sample chain [dubbo-go-pixiu-samples]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on PR #148:
URL: https://github.com/apache/dubbo-go-pixiu-samples/pull/148#issuecomment-4528113945
> > > 这个示例在集成测试里面吗
> >
> >
> > 能的
>
> 那就加一下
好的,已完成
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org