github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/blog/content/slices/prog040.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "bytes" 9 "fmt" 10 ) 11 12 type path []byte 13 14 func (p *path) TruncateAtFinalSlash() { 15 i := bytes.LastIndex(*p, []byte("/")) 16 if i >= 0 { 17 *p = (*p)[0:i] 18 } 19 } 20 21 func main() { 22 pathName := path("/usr/bin/tso") // Conversion from string to path. 23 pathName.TruncateAtFinalSlash() 24 fmt.Printf("%s\n", pathName) 25 }