This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func absPathify(inPath string) string { | |
if strings.HasPrefix(inPath, "$HOME") { | |
inPath = userHomeDir() + inPath[5:] | |
} | |
if strings.HasPrefix(inPath, "$") { | |
end := strings.Index(inPath, string(os.PathSeparator)) | |
inPath = os.Getenv(inPath[1:end]) + inPath[end:] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func exists(path string) (bool, error) { | |
_, err := v.fs.Stat(path) | |
if err == nil { | |
return true, nil | |
} | |
if os.IsNotExist(err) { | |
return false, nil | |
} | |
return false, err | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func NewNotepad(outThreshold Threshold, logThreshold Threshold, outHandle, logHandle io.Writer, prefix string, flags int) *Notepad { | |
n := &Notepad{} | |
n.loggers = [7]**log.Logger{&n.TRACE, &n.DEBUG, &n.INFO, &n.WARN, &n.ERROR, &n.CRITICAL, &n.FATAL} | |
n.outHandle = outHandle | |
n.logHandle = logHandle | |
n.stdoutThreshold = outThreshold | |
n.logThreshold = logThreshold | |
if len(prefix) != 0 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net" | |
"os/exec" | |
"github.com/k0kubun/pp" | |
) | |
func Hosts(cidr string) ([]string, error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check root rights to use system service | |
func checkPrivileges() (bool, error) { | |
if output, err := exec.Command("id", "-g").Output(); err == nil { | |
if gid, parseErr := strconv.ParseUint(strings.TrimSpace(string(output)), 10, 32); parseErr == nil { | |
if gid == 0 { | |
return true, nil | |
} | |
return false, ErrRootPriveleges | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
// Example | |
sci := ServerConnInfo{ | |
"127.0.0.1", | |
"22", | |
"ubuntu", | |
`key.pem`, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
,_---~~~~~----._ | |
_,,_,*^____ _____``*g*\"*, | |
/ __/ /' ^. / \ ^@q f | |
[ @f | @)) | | @)) l 0 _/ | |
\`/ \~____ / __ \_____/ \ | |
| _l__l_ I | |
} [______] I | |
] | | | | | |
] ~ ~ | | |
| | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
) | |
func main() { | |
askCommand := flag.NewFlagSet("ask", flag.ExitOnError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) { | |
// path/to/whatever does not exist | |
} | |
if _, err := os.Stat("/path/to/whatever"); err == nil { | |
// path/to/whatever exists | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package safebuffer | |
import ( | |
"bytes" | |
"sync" | |
) | |
// Buffer is a goroutine safe bytes.Buffer | |
type Buffer struct { | |
buffer bytes.Buffer |
OlderNewer