本文整理匯總了Golang中url.URL.Host方法的典型用法代碼示例。如果您正苦於以下問題:Golang URL.Host方法的具體用法?Golang URL.Host怎麽用?Golang URL.Host使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類url.URL
的用法示例。
在下文中一共展示了URL.Host方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Setup
//.........這裏部分代碼省略.........
" one of three ways, listed in decreasing order of precedence.\n"+
" Note: both values must be supplied using a single method:\n\n"+
" 1. On the command line\n"+
" 2. In the environment variables %s and %s\n"+
" 3. In the file %s as key:secret on a single line\n\n"+
"Options:\n",
os.Args[0], os.Args[0],
s3_access_key_id_variable, s3_secret_access_key_variable, s3_password_file)
flag.PrintDefaults()
}
flag.Parse()
// enforce certain option combinations
if reset {
refresh = true
}
if practice {
watch = false
}
// make sure we get access keys
if accesskeyid == "" || secretaccesskey == "" {
accesskeyid, secretaccesskey = getKeys()
}
if accesskeyid == "" || secretaccesskey == "" {
fmt.Fprintln(os.Stderr, "Error: Amazon AWS Access Key ID and/or Secret Access Key undefined\n")
flag.Usage()
os.Exit(-1)
}
// check command-line arguments
args := flag.Args()
if len(args) != 2 {
flag.Usage()
os.Exit(-1)
}
// figure out the direction of sync, parse the bucket and directory info
var bucketname, bucketprefix, localdir string
switch {
case !strings.HasPrefix(args[0], "s3:") && strings.HasPrefix(args[1], "s3:"):
push = true
localdir = parseLocalDir(args[0])
bucketname, bucketprefix = parseBucket(args[1])
case strings.HasPrefix(args[0], "s3:") && !strings.HasPrefix(args[1], "s3:"):
push = false
bucketname, bucketprefix = parseBucket(args[0])
localdir = parseLocalDir(args[1])
default:
flag.Usage()
os.Exit(-1)
}
// make sure the root directory exists
if info, err := os.Lstat(localdir); err != nil || !info.IsDirectory() {
fmt.Fprintf(os.Stderr, "%s is not a valid directory\n", localdir)
}
// open the database
var err os.Error
var cache Cache
if cache, err = Connect(path.Join(cache_location, bucketname+".sqlite")); err != nil {
fmt.Println("Error connecting to database:", err)
os.Exit(-1)
}
// create the Propolis object
url := new(url.URL)
url.Scheme = "http"
if secure {
url.Scheme = "https"
}
url.Host = bucketname + ".s3.amazonaws.com"
url.Path = "/"
p = &Propolis{
Bucket: bucketname,
Url: url,
Secure: secure,
ReducedRedundancy: reduced,
Key: accesskeyid,
Secret: secretaccesskey,
BucketRoot: bucketprefix,
LocalRoot: localdir,
Refresh: refresh,
Paranoid: paranoid,
Reset: reset,
Directories: directories,
Practice: practice,
Watch: watch,
Delay: delay,
Concurrent: concurrent,
Db: cache,
}
return
}
示例2: getNewUrl
func getNewUrl(url *url.URL) *url.URL {
urlBackend, _ := url.Parse("http://127.0.0.1")
url.Scheme = urlBackend.Scheme
url.Host = urlBackend.Host
return url
}