Help Center> OBS GO SDK> API Reference> Initialization> ObsClient Initialization
Updated on 2022-02-10 GMT+08:00

ObsClient Initialization

API Description

ObsClient functions as the Go client for accessing OBS. It offers users a series of APIs for interaction with OBS. These APIs are used for managing and operating resources, such as buckets and objects, stored in OBS.

Initialization Method

func New(ak, sk, endpoint string, configurers ...configurer) (*ObsClient, error)

Parameter Description

Field

Type

Optional or Mandatory

Description

ak

string

Mandatory

Access key ID (AK)

sk

string

Mandatory

Secret access key (SK)

endpoint

string

Mandatory

Endpoint for accessing OBS, which contains the protocol type, domain name (or IP address), and port ID. For example, https://your-endpoint:443.

You can click here to view the endpoints of OBS.

configurers

configurer (private type contained in the obs package)

Optional

A group of parameters used to configure ObsClient, including connection timeout period, maximum retries, and maximum number of connections.

Available Configurers

Configurer

Description

WithSslVerifyAndPemCerts(sslVerify bool, pemCerts []byte)

Specifies whether to verify server-side certificates. Server-side certificates will not be verified by default.

WithHeaderTimeout(headerTimeout int)

Specifies the timeout period of obtaining the response headers. The default value is 60.

WithMaxConnections(maxConnsPerHost int)

Specifies the maximum number of idle HTTP connections. The default value is 1000.

WithConnectTimeout(connectTimeout int)

Specifies the timeout period for establishing an HTTP/HTTPS connection, in seconds. The default value is 60.

WithSocketTimeout(socketTimeout int)

Specifies the timeout duration for transmitting data at the socket layer, in seconds. The default value is 60.

WithIdleConnTimeout(idleConnTimeout int)

Specifies the timeout period of an idle HTTP connection in the connection pool, in seconds. The default value is 30.

WithMaxRetryCount(maxRetryCount int)

Specifies the maximum number of retries when an HTTP/HTTPS connection is abnormal. The default value is 3.

WithProxyUrl(proxyUrl string)

Configures the HTTP proxy.

WithHttpTransport(transport *http.Transport)

Configures custom structs of the Transport type.

WithRequestContext(ctx context.Context)

Configures the context for each HTTP request.

WithMaxRedirectCount(maxRedirectCount int)

Specifies the maximum number of times that the HTTP/HTTPS request is redirected. The default value is 3.

WithSecurityToken(securityToken string)

Specifies security token in the temporary access keys.

Sample Code

import (
       "obs"
)

var ak = "*** Provide your Access Key ***"
var sk = "*** Provide your Secret Key ***"
var endpoint = "https://your-endpoint"

var obsClient, _ = obs.New(
       ak,
       sk,
       endpoint,
       obs.WithConnectTimeout(30),
       obs.WithSocketTimeout(60),
       obs.WithMaxConnections(100),
       obs.WithMaxRetryCount(3),
)

func main() {
        obsClient.Close()
}