本文整理汇总了Golang中path.Split函数的典型用法代码示例。如果您正苦于以下问题:Golang Split函数的具体用法?Golang Split怎么用?Golang Split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Split函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: filterEventJobCreated
func filterEventJobCreated(resp *etcd.Response) *Event {
if resp.Action != "set" || resp.Node.PrevValue != "" {
return nil
}
dir, jobName := path.Split(resp.Node.Key)
dir = strings.TrimSuffix(dir, "/")
dir, prefix := path.Split(dir)
if prefix != strings.Trim(schedulePrefix, "/") {
return nil
}
var jp job.JobPayload
err := unmarshal(resp.Node.Value, &jp)
if err != nil {
log.V(1).Infof("Failed to deserialize JobPayload: %s", err)
return nil
}
j, _ := job.NewJob(jobName, nil, &jp)
dir = strings.TrimSuffix(dir, "/")
dir, machName := path.Split(dir)
m := machine.New(machName)
return &Event{"EventJobCreated", *j, m}
}
示例2: Open
// for direct zk connection: vtzk://host:port/cell/keyspace/tabletType
// we always use a MetaConn, host and port are ignored.
// the driver name dictates if we use zk or zkocc, and streaming or not
//
// if user and password are specified in the URL, they will be used
// for each DB connection to the tablet's vttablet processes
func (driver *sDriver) Open(name string) (sc db.Conn, err error) {
if !strings.HasPrefix(name, "vtzk://") {
// add a default protocol talking to zk
name = "vtzk://" + name
}
u, err := url.Parse(name)
if err != nil {
return nil, err
}
dbi, tabletType := path.Split(u.Path)
dbi = strings.Trim(dbi, "/")
tabletType = strings.Trim(tabletType, "/")
cell, keyspace := path.Split(dbi)
cell = strings.Trim(cell, "/")
keyspace = strings.Trim(keyspace, "/")
var user, password string
if u.User != nil {
user = u.User.Username()
var ok bool
password, ok = u.User.Password()
if !ok {
return nil, fmt.Errorf("vt: need a password if a user is specified")
}
}
return Dial(driver.ts, cell, keyspace, topo.TabletType(tabletType), driver.stream, tablet.DefaultTimeout, user, password)
}
示例3: filterEventJobUnscheduled
func filterEventJobUnscheduled(resp *goetcd.Response) *event.Event {
if resp.Action != "delete" && resp.Action != "compareAndDelete" {
return nil
}
dir, baseName := path.Split(resp.Node.Key)
if baseName != "target" {
return nil
}
dir = strings.TrimSuffix(dir, "/")
dir, jobName := path.Split(dir)
dir = strings.TrimSuffix(dir, "/")
dir, prefixName := path.Split(dir)
if prefixName != jobPrefix {
return nil
}
if resp.PrevNode == nil {
return nil
}
return &event.Event{"EventJobUnscheduled", jobName, resp.PrevNode.Value}
}
示例4: statesByMUSKey
// statesByMUSKey returns a map of all UnitStates stored in the registry indexed by MUSKey
func (r *EtcdRegistry) statesByMUSKey() (map[MUSKey]*unit.UnitState, error) {
mus := make(map[MUSKey]*unit.UnitState)
req := etcd.Get{
Key: path.Join(r.keyPrefix, statesPrefix),
Recursive: true,
}
res, err := r.etcd.Do(&req)
if err != nil && !etcd.IsKeyNotFound(err) {
return nil, err
}
if res != nil {
for _, dir := range res.Node.Nodes {
_, name := path.Split(dir.Key)
for _, node := range dir.Nodes {
_, machID := path.Split(node.Key)
var usm unitStateModel
if err := unmarshal(node.Value, &usm); err != nil {
log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
continue
}
us := modelToUnitState(&usm, name)
if us != nil {
key := MUSKey{name, machID}
mus[key] = us
}
}
}
}
return mus, nil
}
示例5: stateByMUSKey
// stateByMUSKey returns a single UnitState stored in the registry indexed by MUSKey
// that matches with the given unit name
func (r *EtcdRegistry) stateByMUSKey(uName string) (*unit.UnitState, error) {
key := r.prefixed(statesPrefix)
opts := &etcd.GetOptions{
Recursive: true,
}
res, err := r.kAPI.Get(context.Background(), key, opts)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return nil, err
}
if res == nil {
return nil, nil
}
for _, dir := range res.Node.Nodes {
_, name := path.Split(dir.Key)
if name != uName {
continue
}
for _, node := range dir.Nodes {
_, machID := path.Split(node.Key)
var usm unitStateModel
if err := unmarshal(node.Value, &usm); err != nil {
log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
continue
}
us := modelToUnitState(&usm, name)
if us != nil {
return us, nil
}
}
}
return nil, nil
}
示例6: FileOutput
// 输出文件。
// name指定文件名,为空时默认保持原文件名不变。
func (self *Context) FileOutput(name ...string) {
_, s := path.Split(self.GetUrl())
n := strings.Split(s, "?")[0]
// 初始化
baseName := strings.Split(n, ".")[0]
ext := path.Ext(n)
if len(name) > 0 {
p, n := path.Split(name[0])
if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" {
baseName = p + baseName2
}
if ext == "" {
ext = path.Ext(n)
}
}
if ext == "" {
ext = ".html"
}
self.Lock()
self.files = append(self.files, data.GetFileCell(self.GetRuleName(), baseName+ext, self.Response.Body))
self.Unlock()
}
示例7: statesByMUSKey
// statesByMUSKey returns a map of all UnitStates stored in the registry indexed by MUSKey
func (r *EtcdRegistry) statesByMUSKey() (map[MUSKey]*unit.UnitState, error) {
mus := make(map[MUSKey]*unit.UnitState)
key := r.prefixed(statesPrefix)
opts := &etcd.GetOptions{
Recursive: true,
}
res, err := r.kAPI.Get(r.ctx(), key, opts)
if err != nil && !isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
return nil, err
}
if res != nil {
for _, dir := range res.Node.Nodes {
_, name := path.Split(dir.Key)
for _, node := range dir.Nodes {
_, machID := path.Split(node.Key)
var usm unitStateModel
if err := unmarshal(node.Value, &usm); err != nil {
log.Errorf("Error unmarshalling UnitState(%s) from Machine(%s): %v", name, machID, err)
continue
}
us := modelToUnitState(&usm, name)
if us != nil {
key := MUSKey{name, machID}
mus[key] = us
}
}
}
}
return mus, nil
}
示例8: AddFile
// AddFile saves to Response.Files preparing for Pipeline
func (self *Response) AddFile(name ...string) {
file := map[string]interface{}{
"Body": self.Response.Body,
}
_, s := path.Split(self.GetUrl())
n := strings.Split(s, "?")[0]
// 初始化
baseName := strings.Split(n, ".")[0]
ext := path.Ext(n)
if len(name) > 0 {
_, n = path.Split(name[0])
if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" {
baseName = baseName2
}
if ext == "" {
ext = path.Ext(n)
}
}
if ext == "" {
ext = ".html"
}
file["Name"] = baseName + ext
self.files = append(self.files, file)
}
示例9: main
func main() {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
fmt.Println("working directory: ", wd)
fmt.Println("base: ", path.Base(wd))
fmt.Println("dir: ", path.Dir(wd))
fmt.Println("ext: ", path.Ext(wd+"howdy.test"))
fmt.Println("abs: ", path.IsAbs(wd))
fmt.Println("abs: ", path.IsAbs("howdy/../../"))
dirty := "////howdy////lots/of//slashes//yeah/"
fmt.Println("dirty: ", dirty)
fmt.Println("clean: ", path.Clean(dirty))
fmt.Println("joined: ", path.Join("one", "two", "three", "four"))
dir, file := path.Split(wd + "/lala.txt")
fmt.Println("dir: ", dir, " file: ", file)
// Hmmmm, I wonder if path works with URLs.
var base string
url := "http://example.com/test/file.txt"
base, file = path.Split(url)
fmt.Printf("Got base %v and file %v\n", base, file)
// Looks like the double slash after http: gets messed up by path.Dir.
fmt.Printf("Base is %v\nDir is %v\n", path.Base(url), path.Dir(url))
}
示例10: FileOutput
// 输出文件。
// name指定文件名,为空时默认保持原文件名不变。
func (self *Context) FileOutput(name ...string) {
// 读取完整文件流
bytes, err := ioutil.ReadAll(self.Response.Body)
self.Response.Body.Close()
if err != nil {
panic(err.Error())
return
}
// 智能设置完整文件名
_, s := path.Split(self.GetUrl())
n := strings.Split(s, "?")[0]
baseName := strings.Split(n, ".")[0]
var ext string
if len(name) > 0 {
p, n := path.Split(name[0])
if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" {
baseName = p + baseName2
}
ext = path.Ext(n)
}
if ext == "" {
ext = path.Ext(n)
}
if ext == "" {
ext = ".html"
}
// 保存到文件临时队列
self.Lock()
self.files = append(self.files, data.GetFileCell(self.GetRuleName(), baseName+ext, bytes))
self.Unlock()
}
示例11: NewReplacer
// NewReplacer makes a new replacer based on r and rr.
// Do not create a new replacer until r and rr have all
// the needed values, because this function copies those
// values into the replacer. rr may be nil if it is not
// available. emptyValue should be the string that is used
// in place of empty string (can still be empty string).
func NewReplacer(r *http.Request, rr *responseRecorder, emptyValue string) Replacer {
rep := replacer{
replacements: map[string]string{
"{method}": r.Method,
"{scheme}": func() string {
if r.TLS != nil {
return "https"
}
return "http"
}(),
"{host}": r.Host,
"{path}": r.URL.Path,
"{query}": r.URL.RawQuery,
"{fragment}": r.URL.Fragment,
"{proto}": r.Proto,
"{remote}": func() string {
if fwdFor := r.Header.Get("X-Forwarded-For"); fwdFor != "" {
return fwdFor
}
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
return r.RemoteAddr
}
return host
}(),
"{port}": func() string {
_, port, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
return ""
}
return port
}(),
"{uri}": r.URL.RequestURI(),
"{when}": func() string {
return time.Now().Format(timeFormat)
}(),
"{file}": func() string {
_, file := path.Split(r.URL.Path)
return file
}(),
"{dir}": func() string {
dir, _ := path.Split(r.URL.Path)
return dir
}(),
},
emptyValue: emptyValue,
}
if rr != nil {
rep.replacements["{status}"] = strconv.Itoa(rr.status)
rep.replacements["{size}"] = strconv.Itoa(rr.size)
rep.replacements["{latency}"] = time.Since(rr.start).String()
}
// Header placeholders
for header, val := range r.Header {
rep.replacements[headerReplacer+header+"}"] = strings.Join(val, ",")
}
return rep
}
示例12: getProgramPath
func getProgramPath() (string, os.Error) {
program := os.Args[0]
dir, _ := path.Split(program)
if dir == "" {
binPath, pathError := exec.LookPath(program)
if pathError != nil {
if syscall.Access(program, syscall.O_RDONLY) != 0 {
return "", os.NewError("Path to " + program + " couldn't be found")
}
cwd, cwdError := os.Getwd()
if cwdError != nil {
return "", cwdError
}
return cwd, nil
}
binPath, _ = path.Split(binPath)
return binPath, nil
}
dir, _ = abspath(dir)
return dir, nil
}
示例13: getProjectInfo
func getProjectInfo(filename string) (projectDir string, sources map[string]string, specialPackages map[string][]string, ok bool) {
projectDir, _ = path.Split(filename)
projectDir = projectDir[:len(projectDir)-1]
projectDir, _ = path.Split(projectDir)
for {
projectDir = projectDir[:len(projectDir)-1]
if projectDir == "" {
return "", nil, nil, false
}
//fmt.Println(projectDir)
fd, _ := os.Open(projectDir)
list, _ := fd.Readdir(-1)
for i := 0; i < len(list); i++ {
d := &list[i]
if d.Name == "goref.cfg" {
srcs, specialPacks, ok := getInfo(projectDir, path.Join(projectDir, d.Name))
if !ok {
return "", nil, nil, false
}
return projectDir, srcs, specialPacks, true
}
}
projectDir, _ = path.Split(projectDir)
fd.Close()
}
return "", nil, nil, false
}
示例14: Mv
// Mv moves the file or directory at 'src' to 'dst'
func Mv(r *Root, src, dst string) error {
srcDir, srcFname := gopath.Split(src)
var dstDirStr string
var filename string
if dst[len(dst)-1] == '/' {
dstDirStr = dst
filename = srcFname
} else {
dstDirStr, filename = gopath.Split(dst)
}
// get parent directories of both src and dest first
dstDir, err := lookupDir(r, dstDirStr)
if err != nil {
return err
}
srcDirObj, err := lookupDir(r, srcDir)
if err != nil {
return err
}
srcObj, err := srcDirObj.Child(srcFname)
if err != nil {
return err
}
nd, err := srcObj.GetNode()
if err != nil {
return err
}
fsn, err := dstDir.Child(filename)
if err == nil {
switch n := fsn.(type) {
case *File:
_ = dstDir.Unlink(filename)
case *Directory:
dstDir = n
default:
return fmt.Errorf("unexpected type at path: %s", dst)
}
} else if err != os.ErrNotExist {
return err
}
err = dstDir.AddChild(filename, nd)
if err != nil {
return err
}
err = srcDirObj.Unlink(srcFname)
if err != nil {
return err
}
return nil
}
示例15: TrimSourceFile
// TrimSourceFile shortens DCCP source file names for readability
func TrimSourceFile(sfile string) string {
sdir, sfile := path.Split(sfile)
if len(sdir) > 0 {
_, sdir = path.Split(sdir[:len(sdir)-1])
}
sfile = path.Join(sdir, sfile)
return sfile
}