本文整理汇总了Golang中google/golang.org/cloud.WithEndpoint函数的典型用法代码示例。如果您正苦于以下问题:Golang WithEndpoint函数的具体用法?Golang WithEndpoint怎么用?Golang WithEndpoint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithEndpoint函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewClient
// NewClient creates a new PubSub client.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
var o []cloud.ClientOption
// Environment variables for gcloud emulator:
// https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub/
if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" {
o = []cloud.ClientOption{
cloud.WithEndpoint("http://" + addr + "/"),
cloud.WithBaseHTTP(http.DefaultClient),
}
} else {
o = []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(raw.PubsubScope, raw.CloudPlatformScope),
cloud.WithUserAgent(userAgent),
}
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
s, err := newPubSubService(httpClient, endpoint)
if err != nil {
return nil, fmt.Errorf("constructing pubsub client: %v", err)
}
c := &Client{
projectID: projectID,
s: s,
}
return c, nil
}
开发者ID:Ropes,项目名称:pubbing,代码行数:35,代码来源:pubsub.go
示例2: NewClient
// NewClient returns a new log client, logging to the named log in the
// provided project.
//
// The exported fields on the returned client may be modified before
// the client is used for logging. Once log entries are in flight,
// the fields must not be modified.
func NewClient(ctx context.Context, projectID, logName string, opts ...cloud.ClientOption) (*Client, error) {
httpClient, endpoint, err := transport.NewHTTPClient(ctx, append([]cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(Scope),
cloud.WithUserAgent(userAgent),
}, opts...)...)
if err != nil {
return nil, err
}
svc, err := api.New(httpClient)
if err != nil {
return nil, err
}
svc.BasePath = endpoint
c := &Client{
svc: svc,
logs: api.NewProjectsLogsEntriesService(svc),
logName: logName,
projID: projectID,
}
for i := range c.writer {
level := Level(i)
c.writer[level] = levelWriter{level, c}
c.logger[level] = log.New(c.writer[level], "", 0)
}
return c, nil
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:33,代码来源:logging.go
示例3: NewClient
// NewClient creates a new Client for a given dataset.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(ScopeDatastore, ScopeUserEmail),
cloud.WithUserAgent(userAgent),
}
o = append(o, opts...)
client, err := transport.NewProtoClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
return &Client{
client: client,
dataset: projectID,
}, nil
}
开发者ID:angelabier1,项目名称:pachyderm,代码行数:18,代码来源:datastore.go
示例4: NewClusterAdminClient
// NewClusterAdminClient creates a new ClusterAdminClient for a given project.
func NewClusterAdminClient(ctx context.Context, project string, opts ...cloud.ClientOption) (*ClusterAdminClient, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(clusterAdminAddr),
cloud.WithScopes(ClusterAdminScope),
}
o = append(o, opts...)
conn, err := cloud.DialGRPC(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
return &ClusterAdminClient{
conn: conn,
cClient: btcspb.NewBigtableClusterServiceClient(conn),
project: project,
}, nil
}
开发者ID:christopherhesse,项目名称:disgusting-appengine-context-hack,代码行数:18,代码来源:admin.go
示例5: DefaultClientOptions
// DefaultClientOptions returns the default client options to use for the
// client's gRPC connection.
func DefaultClientOptions(endpoint, scope, userAgent string) ([]cloud.ClientOption, error) {
var o []cloud.ClientOption
// Check the environment variables for the bigtable emulator.
// Dial it directly and don't pass any credentials.
if addr := os.Getenv("BIGTABLE_EMULATOR_HOST"); addr != "" {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("emulator grpc.Dial: %v", err)
}
o = []cloud.ClientOption{cloud.WithBaseGRPC(conn)}
} else {
o = []cloud.ClientOption{
cloud.WithEndpoint(endpoint),
cloud.WithScopes(scope),
cloud.WithUserAgent(userAgent),
}
}
return o, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:21,代码来源:option.go
示例6: NewAdminClient
// NewAdminClient creates a new AdminClient for a given project, zone and cluster.
func NewAdminClient(ctx context.Context, project, zone, cluster string, opts ...cloud.ClientOption) (*AdminClient, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(adminAddr),
cloud.WithScopes(AdminScope),
}
o = append(o, opts...)
conn, err := cloud.DialGRPC(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
return &AdminClient{
conn: conn,
tClient: bttspb.NewBigtableTableServiceClient(conn),
project: project,
zone: zone,
cluster: cluster,
}, nil
}
开发者ID:christopherhesse,项目名称:disgusting-appengine-context-hack,代码行数:20,代码来源:admin.go
示例7: NewClient
// NewClient creates a new Client for a given dataset.
// If the project ID is empty, it is derived from the DATASTORE_PROJECT_ID environment variable.
// If the DATASTORE_EMULATOR_HOST environment variable is set, client will use its value
// to connect to a locally-running datastore emulator.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
var o []cloud.ClientOption
// Environment variables for gcd emulator:
// https://cloud.google.com/datastore/docs/tools/datastore-emulator
// If the emulator is available, dial it directly (and don't pass any credentials).
if addr := os.Getenv("DATASTORE_EMULATOR_HOST"); addr != "" {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("grpc.Dial: %v", err)
}
o = []cloud.ClientOption{cloud.WithBaseGRPC(conn)}
} else {
o = []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(ScopeDatastore),
cloud.WithUserAgent(userAgent),
}
}
// Warn if we see the legacy emulator environment variables.
if os.Getenv("DATASTORE_HOST") != "" && os.Getenv("DATASTORE_EMULATOR_HOST") == "" {
log.Print("WARNING: legacy environment variable DATASTORE_HOST is ignored. Use DATASTORE_EMULATOR_HOST instead.")
}
if os.Getenv("DATASTORE_DATASET") != "" && os.Getenv("DATASTORE_PROJECT_ID") == "" {
log.Print("WARNING: legacy environment variable DATASTORE_DATASET is ignored. Use DATASTORE_PROJECT_ID instead.")
}
if projectID == "" {
projectID = os.Getenv("DATASTORE_PROJECT_ID")
}
if projectID == "" {
return nil, errors.New("datastore: missing project/dataset id")
}
o = append(o, opts...)
conn, err := transport.DialGRPC(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
return &Client{
conn: conn,
client: pb.NewDatastoreClient(conn),
dataset: projectID,
}, nil
}
开发者ID:go-microservices,项目名称:resizer,代码行数:47,代码来源:datastore.go
示例8: CreateGooglePubSubClient
// CreateGooglePubSubClient returns client communicate with google Pub/Sub service
func CreateGooglePubSubClient() (*pubsub.Client, error) {
envValue := os.Getenv(NDGooglePubSubURL)
if envValue != "" {
googlePubSubURL = envValue
}
envValue = os.Getenv(NDGoogleProjectID)
if envValue != "" {
googleProjectID = envValue
}
ctx := cloud.NewContext(googleProjectID, http.DefaultClient)
o := []cloud.ClientOption{
cloud.WithBaseHTTP(http.DefaultClient),
cloud.WithEndpoint(googleDatastoreURL),
}
client, _ := pubsub.NewClient(ctx, googleProjectID, o...)
return client, nil
}
开发者ID:nildev,项目名称:prj-tpl-basic-api,代码行数:20,代码来源:registry.go
示例9: NewClient
// NewClient creates a new Client for a given project, zone and cluster.
func NewClient(ctx context.Context, project, zone, cluster string, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(Scope),
cloud.WithUserAgent(clientUserAgent),
}
o = append(o, opts...)
conn, err := transport.DialGRPC(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
return &Client{
conn: conn,
client: btspb.NewBigtableServiceClient(conn),
project: project,
zone: zone,
cluster: cluster,
}, nil
}
开发者ID:reagere,项目名称:gcloud-golang,代码行数:21,代码来源:bigtable.go
示例10: NewClient
// NewClient create a new PubSub client.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(raw.PubsubScope, raw.CloudPlatformScope),
cloud.WithUserAgent(userAgent),
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
s, err := newPubSubService(httpClient, endpoint)
c := &Client{
projectID: projectID,
s: s,
}
return c, nil
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:22,代码来源:pubsub.go
示例11: newLogTest
func newLogTest(t *testing.T) *logTest {
handlerc := make(chan http.Handler, 1)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
select {
case h := <-handlerc:
h.ServeHTTP(w, r)
default:
slurp, _ := ioutil.ReadAll(r.Body)
t.Errorf("Unexpected HTTP request received: %s", slurp)
w.WriteHeader(500)
io.WriteString(w, "unexpected HTTP request")
}
}))
c, err := NewClient(context.Background(), "PROJ-ID", "LOG-NAME",
cloud.WithEndpoint(ts.URL),
cloud.WithTokenSource(dummyTokenSource{}), // prevent DefaultTokenSource
)
if err != nil {
t.Fatal(err)
}
var clock struct {
sync.Mutex
now time.Time
}
c.timeNow = func() time.Time {
clock.Lock()
defer clock.Unlock()
if clock.now.IsZero() {
clock.now = time.Unix(0, 0)
}
clock.now = clock.now.Add(1 * time.Second)
return clock.now
}
return &logTest{
t: t,
ts: ts,
c: c,
handlerc: handlerc,
}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:40,代码来源:logging_test.go
示例12: NewClient
// NewClient constructs a new Client which can perform BigQuery operations.
// Operations performed via the client are billed to the specified GCP project.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(Scope),
cloud.WithUserAgent(userAgent),
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
s, err := newBigqueryService(httpClient, endpoint)
if err != nil {
return nil, fmt.Errorf("constructing bigquery client: %v", err)
}
c := &Client{
service: s,
projectID: projectID,
}
return c, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:25,代码来源:bigquery.go
示例13: CreateGoogleDatastoreClient
// CreateGoogleDatastoreClient create client to communicate to google Datastore service
func CreateGoogleDatastoreClient() (*datastore.Client, error) {
envValue := os.Getenv(NDGoogleDatastoreURL)
if envValue != "" {
googleDatastoreURL = envValue
}
envValue = os.Getenv(NDGoogleProjectID)
if envValue != "" {
googleProjectID = envValue
}
ctx := cloud.NewContext(googleProjectID, http.DefaultClient)
o := []cloud.ClientOption{
cloud.WithBaseHTTP(http.DefaultClient),
cloud.WithEndpoint(googleDatastoreURL),
}
client, err := datastore.NewClient(ctx, googleProjectID, o...)
if err != nil {
return nil, err
}
return client, nil
}
开发者ID:nildev,项目名称:prj-tpl-basic-api,代码行数:24,代码来源:registry.go
注:本文中的google/golang.org/cloud.WithEndpoint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论