
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
trpc.group/trpc-go/trpc-database/goes
Advanced tools
English | 中文
wrapping community es, used with trpc.
All configuration options are placed within the plugins section, with only the service name retained in the client configuration.
client:
timeout: 1000
namespace: Development
service:
- name: trpc.app.service.es
plugins:
database:
goes:
clientoptions:
- name: trpc.app.service.es # Match the service name in the client configuration
url: http://127.0.0.1:9200 # Elasticsearch address
user: username # Username
password: password # Password
timeout: 1000 # Timeout
log:
enabled: true # Enable logging
request_enabled: true # Print request logs
response_enabled: true # Print response logs
goes supports both Elastic V7 and V8 API versions, and no longer supports V6 API version. The SDK supports three calling methods; details can be found in the code usage examples.
Client.Methodpackage main
import (
"bytes"
"context"
"encoding/json"
"net/http"
"strconv"
"trpc.group/trpc-go/trpc-database/goes"
"github.com/elastic/go-elasticsearch/esapi"
pb "trpc.test.helloworld"
)
var body = map[string]interface{}{
"account_number": 111111,
"firstname": "User",
"city": "Shenzhen",
}
func (s *greeterImpl) SayHello(ctx context.Context, req *pb.HelloRequest) (rsp *pb.HelloReply, err error) {
// Use es v7 API to execute the request
proxyV7, err := goes.NewElasticClientV7("trpc.app.service.es")
if err != nil {
return nil, err
}
jsonBody, err := json.Marshal(body)
if err != nil {
return nil, err
}
_, err = proxyV7.Index("bank", bytes.NewBuffer(jsonBody), proxyV7.Index.WithContext(ctx))
if err != nil {
return nil, err
}
return &pb.HelloReply{}, nil
}
package main
func (s *greeterImpl) SayHello(ctx context.Context, req *pb.HelloRequest) (rsp *pb.HelloReply, err error) {
// Use es v8 API to execute the request
proxyV8, err := goes.NewElasticClientV8("trpc.app.service.es")
if err != nil {
return nil, err
}
jsonBody, err = json.Marshal(body)
if err != nil {
return nil, err
}
_, err = proxyV8.Index("bank", bytes.NewBuffer(jsonBody), proxyV8.Index.WithContext(ctx))
if err != nil {
return nil, err
}
return &pb.HelloReply{}, nil
}
MethodRequest.Dopackage main
func (s *greeterImpl) SayHello(ctx context.Context, req *pb.HelloRequest) (rsp *pb.HelloReply, err error) {
// Use es v7 API to execute the request
proxyV7, err := goes.NewElasticClientV7("trpc.app.service.es")
if err != nil {
return nil, err
}
// Build request using es API
indexRequest := esapi.IndexRequest{
Index: "bank",
DocumentID: strconv.Itoa(1),
Body: bytes.NewReader(jsonBody),
}
// Execute request using trpc goes client
_, err = indexRequest.Do(ctx, proxyV7)
if err != nil {
return nil, err
}
return &pb.HelloReply{}, nil
}
package main
func (s *greeterImpl) SayHello(ctx context.Context, req *pb.HelloRequest) (rsp *pb.HelloReply, err error) {
// Use es v8 API to execute the request
proxyV8, err := goes.NewElasticClientV8("trpc.app.service.es")
if err != nil {
return nil, err
}
// Build request using es API
indexRequestV8 := esapi.IndexRequest{
Index: "bank",
DocumentID: strconv.Itoa(1),
Body: bytes.NewReader(jsonBody),
}
// Execute request using trpc goes client
_, err = indexRequestV8.Do(ctx, proxyV8)
if err != nil {
return nil, err
}
return &pb.HelloReply{}, nil
}
RoundTriper.RoundTripThis method should only be used when fully customizing the es HTTP request is necessary, and in most cases, it is preferable to use the es API for the call.
package main
func (s *greeterImpl) SayHello(ctx context.Context, req *pb.HelloRequest) (rsp *pb.HelloReply, err error) {
url := &url.URL{Path: "/", Scheme: "http"}
proxy := goes.NewClientProxy("trpc.app.service.es")
_, err = proxy.RoundTrip(&http.Request{Method: "GET", Proto: "HTTP/1.1",URL:url, ProtoMajor: 1, ProtoMinor: 1})
if err != nil {
return nil, err
}
return &pb.HelloReply{}, nil
}
NewElasticClientV7 and NewElasticClientV8 methods create a new connection and send a GET request to the es server to verify server information. It is recommended to reuse the same client to achieve connection reuse.FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.