本文整理汇总了Golang中path/filepath.FromSlash函数的典型用法代码示例。如果您正苦于以下问题:Golang FromSlash函数的具体用法?Golang FromSlash怎么用?Golang FromSlash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromSlash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestIsIgnoredFile
func TestIsIgnoredFile(t *testing.T) {
home := osutil.HomeDir()
fullpath := filepath.Join(home, "Downloads", "pony.jpg")
var wantIgnored = map[string]bool{
filepath.Join(home, filepath.FromSlash("Downloads/pony.jpg")): true,
filepath.Join(home, filepath.FromSlash("Downloads/pony.*")): true,
filepath.Join(home, filepath.FromSlash("Downloads/*.jpg")): true,
filepath.Join(home, filepath.FromSlash("Downloads/*")): true,
"*.jpg": true,
"pony.*": true,
"*.foo": false,
"foo.*": false,
filepath.Join(home, "Downloads"): true,
filepath.Join(home, "Down"): false,
filepath.FromSlash("~/Downloads/pony.jpg"): true,
filepath.FromSlash("~/Downloads/pony.*"): true,
filepath.FromSlash("~/Downloads/*.jpg"): true,
filepath.FromSlash("~/Downloads"): true,
filepath.FromSlash("~/Down"): false,
filepath.FromSlash("~/DownloadsAndMore"): false,
home: true,
"Downloads": true,
"Down": false,
}
for pattern, want := range wantIgnored {
ignoreChecker := newIgnoreChecker([]string{pattern})
if ignoreChecker(fullpath) != want {
t.Errorf("%v not ignored; did not match %v", fullpath, pattern)
}
}
}
示例2: TestMissingAttributes
func (s *format_1_18Suite) TestMissingAttributes(c *gc.C) {
logDir, err := paths.LogDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir, err := paths.DataDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir = filepath.FromSlash(realDataDir)
logPath := filepath.Join(logDir, "juju")
logPath = filepath.FromSlash(logPath)
dataDir := c.MkDir()
configPath := filepath.Join(dataDir, agentConfigFilename)
err = utils.AtomicWriteFile(configPath, []byte(configData1_18WithoutUpgradedToVersion), 0600)
c.Assert(err, jc.ErrorIsNil)
readConfig, err := ReadConfig(configPath)
c.Assert(err, jc.ErrorIsNil)
c.Assert(readConfig.UpgradedToVersion(), gc.Equals, version.MustParse("1.16.0"))
configLogDir := filepath.FromSlash(readConfig.LogDir())
configDataDir := filepath.FromSlash(readConfig.DataDir())
c.Assert(configLogDir, gc.Equals, logPath)
c.Assert(configDataDir, gc.Equals, realDataDir)
c.Assert(readConfig.PreferIPv6(), jc.IsFalse)
// The api info doesn't have the environment tag set.
apiInfo, ok := readConfig.APIInfo()
c.Assert(ok, jc.IsTrue)
c.Assert(apiInfo.EnvironTag.Id(), gc.Equals, "")
}
示例3: loadDefaultKeys
func loadDefaultKeys() (auths []ssh.AuthMethod, err error) {
k := ""
currentUser, err := user.Current()
defaultKeyPathA := filepath.FromSlash(currentUser.HomeDir + "/.ssh/id_rsa")
defaultKeyPathB := filepath.FromSlash(currentUser.HomeDir + "/ssh/id_rsa")
if fileExists(defaultKeyPathA) {
k = defaultKeyPathA
} else if fileExists(defaultKeyPathB) {
k = defaultKeyPathB
}
if len(k) == 0 {
err = errors.New("No key specified")
return
}
pemBytes, err := ioutil.ReadFile(k)
if err != nil {
return
}
signer, err := ssh.ParsePrivateKey(pemBytes)
if err != nil {
return
}
auths = []ssh.AuthMethod{ssh.PublicKeys(signer)}
return
}
示例4: genSearchTypes
// genSearchTypes duplicates some of the camlistore.org/pkg/search types into
// camlistore.org/app/publisher/js/zsearch.go , because it's too costly (in output
// file size) for now to import the search pkg into gopherjs.
func genSearchTypes() error {
sourceFile := filepath.Join(buildSrcDir, filepath.FromSlash("pkg/search/describe.go"))
outputFile := filepath.Join(buildSrcDir, filepath.FromSlash("app/publisher/js/zsearch.go"))
fi1, err := os.Stat(sourceFile)
if err != nil {
return err
}
fi2, err := os.Stat(outputFile)
if err != nil && !os.IsNotExist(err) {
return err
}
if err == nil && fi2.ModTime().After(fi1.ModTime()) {
wantDestFile[outputFile] = true
return nil
}
args := []string{"generate", "camlistore.org/app/publisher/js"}
cmd := exec.Command("go", args...)
cmd.Env = append(cleanGoEnv(),
"GOPATH="+buildGoPath,
)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("go generate for publisher js error: %v, %v", err, string(out))
}
wantDestFile[outputFile] = true
log.Printf("generated %v", outputFile)
return nil
}
示例5: TestGetRelativePath
func TestGetRelativePath(t *testing.T) {
tests := []struct {
path string
base string
expect interface{}
}{
{filepath.FromSlash("/a/b"), filepath.FromSlash("/a"), filepath.FromSlash("b")},
{filepath.FromSlash("/a/b/c/"), filepath.FromSlash("/a"), filepath.FromSlash("b/c/")},
{filepath.FromSlash("/c"), filepath.FromSlash("/a/b"), filepath.FromSlash("../../c")},
{filepath.FromSlash("/c"), "", false},
}
for i, this := range tests {
// ultimately a fancy wrapper around filepath.Rel
result, err := GetRelativePath(this.path, this.base)
if b, ok := this.expect.(bool); ok && !b {
if err == nil {
t.Errorf("[%d] GetRelativePath didn't return an expected error", i)
}
} else {
if err != nil {
t.Errorf("[%d] GetRelativePath failed: %s", i, err)
continue
}
if result != this.expect {
t.Errorf("[%d] GetRelativePath got %v but expected %v", i, result, this.expect)
}
}
}
}
示例6: pkgPath
func (d *VersionHandler) pkgPath(pkg string) string {
root, sub := util.NormalizeName(pkg)
// For the parent applications source skip the cache.
if root == d.Config.Name {
pth := gpath.Basepath()
return filepath.Join(pth, filepath.FromSlash(sub))
}
dep := d.Config.Imports.Get(root)
if dep == nil {
dep = d.Config.DevImports.Get(root)
}
if dep == nil {
dep, _ = d.Use.Get(root)
if dep == nil {
dep = &cfg.Dependency{Name: root}
}
}
key, err := cache.Key(dep.Remote())
if err != nil {
msg.Die("Error generating cache key for %s", dep.Name)
}
return filepath.Join(cache.Location(), "src", key, filepath.FromSlash(sub))
}
示例7: TargetPath
func (p *Page) TargetPath() (outfile string) {
// Always use Url if it's specified
if len(strings.TrimSpace(p.Url)) > 2 {
outfile = strings.TrimSpace(p.Url)
if strings.HasSuffix(outfile, "/") {
outfile = outfile + "index.html"
}
outfile = filepath.FromSlash(outfile)
return
}
// If there's a Permalink specification, we use that
if override, ok := p.Site.Permalinks[p.Section()]; ok {
var err error
outfile, err = override.Expand(p)
if err == nil {
if strings.HasSuffix(outfile, "/") {
outfile += "index.html"
}
outfile = filepath.FromSlash(outfile)
return
}
}
if len(strings.TrimSpace(p.Slug)) > 0 {
outfile = strings.TrimSpace(p.Slug) + "." + p.Extension()
} else {
// Fall back to filename
outfile = helpers.ReplaceExtension(p.Source.LogicalName(), p.Extension())
}
return filepath.Join(p.Source.Dir(), strings.TrimSpace(outfile))
}
示例8: Run
func (container *container) Run(spec garden.ProcessSpec, processIO garden.ProcessIO) (garden.Process, error) {
cmd := exec.Command(filepath.FromSlash(spec.Path), spec.Args...)
cmd.Dir = filepath.Join(container.workDir, filepath.FromSlash(spec.Dir))
cmd.Env = append(os.Environ(), append(container.env, spec.Env...)...)
return container.processTracker.Run(cmd, processIO, spec.TTY)
}
示例9: copylocal
func copylocal(s string) error {
r, err := http.Get("http://uec-images.ubuntu.com/" + s)
if err != nil {
return fmt.Errorf("get %q: %v", s, err)
}
defer r.Body.Close()
if r.StatusCode != 200 {
return fmt.Errorf("status on %q: %s", s, r.Status)
}
path := filepath.Join(filepath.FromSlash(imagesRoot), filepath.FromSlash(s))
d, _ := filepath.Split(path)
if err := os.MkdirAll(d, 0777); err != nil {
return err
}
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
_, err = io.Copy(file, r.Body)
if err != nil {
return fmt.Errorf("error copying image file: %v", err)
}
return nil
}
示例10: Unzip
// Unzip is an exported method which sanitizes io paths and starts unzipping
func Unzip(src, dst string) error {
z := &unzipper{
src: filepath.Clean(filepath.FromSlash(src)),
dst: filepath.Clean(filepath.FromSlash(dst)),
}
return z.do()
}
示例11: Untar
func Untar(src, dst string) error {
t := &untarmonster{
src: filepath.Clean(filepath.FromSlash(src)),
dst: filepath.Clean(filepath.FromSlash(dst)),
}
return t.do()
}
示例12: TestMissingAttributes
func (s *format_1_16Suite) TestMissingAttributes(c *gc.C) {
logDir, err := paths.LogDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir, err := paths.DataDir(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
realDataDir = filepath.FromSlash(realDataDir)
logPath := filepath.Join(logDir, "juju")
logPath = filepath.FromSlash(logPath)
dataDir := c.MkDir()
formatPath := filepath.Join(dataDir, legacyFormatFilename)
err = utils.AtomicWriteFile(formatPath, []byte(legacyFormatFileContents), 0600)
c.Assert(err, jc.ErrorIsNil)
configPath := filepath.Join(dataDir, agentConfigFilename)
err = utils.AtomicWriteFile(configPath, []byte(configDataWithoutNewAttributes), 0600)
c.Assert(err, jc.ErrorIsNil)
readConfig, err := ReadConfig(configPath)
c.Assert(err, jc.ErrorIsNil)
c.Assert(readConfig.UpgradedToVersion(), gc.Equals, version.MustParse("1.16.0"))
configLogDir := filepath.FromSlash(readConfig.LogDir())
configDataDir := filepath.FromSlash(readConfig.DataDir())
c.Assert(configLogDir, gc.Equals, logPath)
c.Assert(configDataDir, gc.Equals, realDataDir)
// Test data doesn't include a StateServerKey so StateServingInfo
// should *not* be available
_, available := readConfig.StateServingInfo()
c.Assert(available, jc.IsFalse)
}
示例13: TestYAMLMenuWithMultipleEntries
// Issue #1934
func TestYAMLMenuWithMultipleEntries(t *testing.T) {
viper.Reset()
defer viper.Reset()
ps1 := []byte(`---
title: "Yaml 1"
weight: 5
menu: ["p_one", "p_two"]
---
Yaml Front Matter with Menu Pages`)
ps2 := []byte(`---
title: "Yaml 2"
weight: 5
menu:
p_three:
p_four:
---
Yaml Front Matter with Menu Pages`)
s := setupMenuTests(t, []source.ByteSource{
{filepath.FromSlash("sect/yaml1.md"), ps1},
{filepath.FromSlash("sect/yaml2.md"), ps2}})
p1 := s.Pages[0]
assert.Len(t, p1.Menus(), 2, "List YAML")
p2 := s.Pages[1]
assert.Len(t, p2.Menus(), 2, "Map YAML")
}
示例14: SetCamdevVars
func (e *Env) SetCamdevVars(altkey bool) {
e.Set("CAMLI_CONFIG_DIR", filepath.Join("config", "dev-client-dir"))
e.Set("CAMLI_AUTH", "userpass:camlistore:pass3179")
e.Set("CAMLI_DEV_KEYBLOBS", filepath.FromSlash("config/dev-client-dir/keyblobs"))
secring := defaultSecring
identity := defaultIdentity
if altkey {
secring = filepath.FromSlash("pkg/jsonsign/testdata/password-foo-secring.gpg")
identity = "C7C3E176"
println("**\n** Note: password is \"foo\"\n**\n")
} else {
if *flagSecretRing != "" {
secring = *flagSecretRing
}
if *flagIdentity != "" {
identity = *flagIdentity
}
}
entity, err := jsonsign.EntityFromSecring(identity, secring)
if err != nil {
panic(err)
}
armoredPublicKey, err := jsonsign.ArmoredPublicKey(entity)
if err != nil {
panic(err)
}
pubKeyRef := blob.SHA1FromString(armoredPublicKey)
e.Set("CAMLI_SECRET_RING", secring)
e.Set("CAMLI_KEYID", identity)
e.Set("CAMLI_PUBKEY_BLOBREF", pubKeyRef.String())
}
示例15: TestConfig_LoadConfigsFileOrder
func TestConfig_LoadConfigsFileOrder(t *testing.T) {
config1, err := LoadConfigDir("test-resources/etcnomad")
if err != nil {
t.Fatalf("Failed to load config: %s", err)
}
config2, err := LoadConfig("test-resources/myconf")
if err != nil {
t.Fatalf("Failed to load config: %s", err)
}
expected := []string{
// filepath.FromSlash changes these to backslash \ on Windows
filepath.FromSlash("test-resources/etcnomad/common.hcl"),
filepath.FromSlash("test-resources/etcnomad/server.json"),
filepath.FromSlash("test-resources/myconf"),
}
config := config1.Merge(config2)
if !reflect.DeepEqual(config.Files, expected) {
t.Errorf("Loaded configs don't match\nwant: %+v\n got: %+v\n",
expected, config.Files)
}
}