Use AddUserAgent function and make appropriate changes in mc
This commit is contained in:
Generated
+1
-1
@@ -36,7 +36,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/objectstorage-go",
|
||||
"Rev": "cb9c9c50825bf5c0758ed9e2f8b8a1414d21b3d2"
|
||||
"Rev": "e0670aef1a63a46d0dc5dc2dba2088f55b73b4b5"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/shiena/ansicolor",
|
||||
|
||||
+12
-7
@@ -20,7 +20,6 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -133,8 +132,10 @@ type Config struct {
|
||||
|
||||
// Advanced options
|
||||
AcceptType string // specify this to get server response in non XML style if server supports it
|
||||
UserAgent string // user override useful when objectstorage-go is used with in your application
|
||||
Transport http.RoundTripper // custom transport usually for debugging, by default its nil
|
||||
// internal
|
||||
// use AddUserAgent append to default, useful when objectstorage-go is used with in your application
|
||||
userAgent string
|
||||
}
|
||||
|
||||
// MustGetEndpoint makes sure that a valid endpoint is provided all the time, even with false regions it will fall
|
||||
@@ -163,18 +164,22 @@ func (c *Config) MustGetEndpoint() string {
|
||||
return getEndpoint(c.Region)
|
||||
}
|
||||
|
||||
// AddUserAgent - append to a default user agent
|
||||
func (c *Config) AddUserAgent(name string, version string, comments ...string) {
|
||||
if name != "" && version != "" {
|
||||
newUserAgent := name + "/" + version + " (" + strings.Join(comments, ", ") + ") "
|
||||
c.userAgent = c.userAgent + " " + newUserAgent
|
||||
}
|
||||
}
|
||||
|
||||
// Global constants
|
||||
const (
|
||||
LibraryName = "objectstorage-go/"
|
||||
LibraryName = "objectstorage-go"
|
||||
LibraryVersion = "0.1"
|
||||
)
|
||||
|
||||
// New - instantiate a new minio api client
|
||||
func New(config *Config) API {
|
||||
// if not UserAgent provided set it to default
|
||||
if strings.TrimSpace(config.UserAgent) == "" {
|
||||
config.UserAgent = LibraryName + " (" + LibraryVersion + "; " + runtime.GOOS + "; " + runtime.GOARCH + ")"
|
||||
}
|
||||
return &api{&lowLevelAPI{config}}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -23,6 +23,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -76,7 +77,8 @@ func newRequest(op *operation, config *Config, body io.ReadSeeker) (*request, er
|
||||
}
|
||||
|
||||
// set UserAgent
|
||||
req.Header.Set("User-Agent", config.UserAgent)
|
||||
config.userAgent = config.userAgent + LibraryName + "/" + LibraryVersion + " (" + runtime.GOOS + ", " + runtime.GOARCH + ") "
|
||||
req.Header.Set("User-Agent", config.userAgent)
|
||||
|
||||
// set Accept header for response encoding style, if available
|
||||
if config.AcceptType != "" {
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/client/fs"
|
||||
@@ -68,6 +70,9 @@ func getNewClient(urlStr string, auth *hostConfig, debug bool) (clnt client.Clie
|
||||
s3Config := new(s3.Config)
|
||||
s3Config.AccessKeyID = auth.AccessKeyID
|
||||
s3Config.SecretAccessKey = auth.SecretAccessKey
|
||||
s3Config.AppName = "Minio"
|
||||
s3Config.AppVersion = Version
|
||||
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
|
||||
s3Config.HostURL = urlStr
|
||||
s3Config.Debug = debug
|
||||
return s3.New(s3Config), nil
|
||||
|
||||
@@ -34,6 +34,9 @@ type Config struct {
|
||||
AccessKeyID string
|
||||
SecretAccessKey string
|
||||
HostURL string
|
||||
AppName string
|
||||
AppVersion string
|
||||
AppComments []string
|
||||
Debug bool
|
||||
|
||||
// Used for SSL transport layer
|
||||
@@ -88,6 +91,7 @@ func New(config *Config) client.Client {
|
||||
objectstorageConf.AccessKeyID = config.AccessKeyID
|
||||
objectstorageConf.SecretAccessKey = config.SecretAccessKey
|
||||
objectstorageConf.Transport = transport
|
||||
objectstorageConf.AddUserAgent(config.AppName, config.AppVersion, config.AppComments...)
|
||||
objectstorageConf.Region = getRegion(u.Host)
|
||||
objectstorageConf.Endpoint = u.Scheme + "://" + u.Host
|
||||
api := objectstorage.New(objectstorageConf)
|
||||
|
||||
Reference in New Issue
Block a user