7
0

init project

This commit is contained in:
liangzy 2020-08-03 20:48:58 +08:00
parent e4d40b6155
commit df72079e6f
9 changed files with 168 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
# Created by .ignore support plugin (hsz.mobi)
### Example user template template
### Example user template
# IntelliJ project files
.idea
*.iml
out
gen

6
sdk/auth/crediantial.go Normal file
View File

@ -0,0 +1,6 @@
package auth
type Creditial struct {
AccessKeyId string
AccessKeySecret string
}

101
sdk/client.go Normal file
View File

@ -0,0 +1,101 @@
package sdk
import (
"context"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/request"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/response"
"net"
"net/http"
"runtime"
"strings"
"time"
)
var Version = "0.0.1"
var defaultConnectTimeout = 5 * time.Second
var defaultReadTimeout = 10 * time.Second
var DefaultUserAgent = fmt.Sprintf("GaoreGoSdk (%s;%s) Golang/%s Core/%s", runtime.GOOS, runtime.GOARCH, strings.Trim(runtime.Version(), "go"), Version)
type Client struct {
Host string
httpClient *http.Client
isInsecure bool
signer *auth.Creditial
readTimeout time.Duration
connectTimeout time.Duration
config *Config
}
func (client *Client) InitWithOptions(host string, config *Config, creditial auth.Creditial) (err error) {
client.httpClient = &http.Client{}
if config.Transport != nil {
client.httpClient.Transport = config.Transport
} else if config.HttpTransport != nil {
client.httpClient.Transport = config.HttpTransport
}
if config.Timeout > 0 {
client.httpClient.Timeout = config.Timeout
}
return nil
}
func (client *Client) InitWithConfig() (config *Config) {
if client.config != nil {
return client.config
} else {
return NewConfig()
}
}
func Timeout(connectTimeout time.Duration) func(ctx context.Context, net, addr string) (c net.Conn, err error) {
return func(ctx context.Context, network, address string) (c net.Conn, err error) {
return (&net.Dialer{
Timeout: connectTimeout,
DualStack: true,
}).DialContext(ctx, network, address)
}
}
func (client *Client) setTimeOut(request request.AcsRequest) {
readTimeout, connectTimeout := client.getTimeOut(request)
client.httpClient.Timeout = readTimeout
if trans, ok := client.httpClient.Transport.(*http.Transport); ok && trans != nil {
trans.DialContext = Timeout(connectTimeout)
client.httpClient.Transport = trans
} else if client.httpClient.Transport == nil {
client.httpClient.Transport = &http.Transport{
DialContext: Timeout(connectTimeout),
}
}
}
func (client *Client) getTimeOut(request request.AcsRequest) (time.Duration, time.Duration) {
readTimeOut := defaultReadTimeout
connectTimeOut := defaultConnectTimeout
reqReadTimeout := request.GetReadTimeout()
reqConnectTimeout := request.GetConnectTimeout()
if reqReadTimeout != 0*time.Millisecond {
readTimeOut = reqReadTimeout
} else if client.readTimeout != 0*time.Microsecond {
readTimeOut = client.readTimeout
} else if client.httpClient.Timeout != 0 {
readTimeOut = client.httpClient.Timeout
}
if reqConnectTimeout != 0*time.Microsecond {
connectTimeOut = reqConnectTimeout
} else if client.connectTimeout != 0*time.Millisecond {
connectTimeOut = client.connectTimeout
}
return readTimeOut, connectTimeOut
}
func (client *Client) DoAction(request request.AcsRequest, response response.AcsResponse) (err error) {
return nil
}

16
sdk/config.go Normal file
View File

@ -0,0 +1,16 @@
package sdk
import (
"net/http"
"time"
)
type Config struct {
Timeout time.Duration
HttpTransport *http.Transport `default:""`
Transport http.RoundTripper `default:""`
}
func NewConfig() *Config {
return &Config{}
}

15
sdk/request/request.go Normal file
View File

@ -0,0 +1,15 @@
package request
import "time"
type AcsRequest interface {
GetReadTimeout() time.Duration
GetConnectTimeout() time.Duration
SetReadTimeout(readTimeOut time.Duration)
SetConnectTimeout(connectTimeOut time.Duration)
}
type baseRequest struct {
Scheme string
Method string
}

View File

@ -0,0 +1,5 @@
package request
type RpcRequest struct {
*baseRequest
}

4
sdk/response/response.go Normal file
View File

@ -0,0 +1,4 @@
package response
type AcsResponse interface {
}

11
services/jedi/client.go Normal file
View File

@ -0,0 +1,11 @@
package jedi
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
type Client struct {
sdk.Client
}
func NewClientWithAccessKey(accesskey, secrect string) *Client {
return nil
}

View File

@ -0,0 +1 @@
package jedi