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