123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- package com_test
- import (
- "fmt"
- "io/ioutil"
- "net/http"
- "notabug.org/makenotabuggreatagain/com"
- )
- func ExampleColorLogS() {
- coloredLog := com.ColorLogS(fmt.Sprintf(
- "[WARN] This is a tesing log that should be colored, path( %s ),"+
- " highlight # %s #, error [ %s ].",
- "path to somewhere", "highlighted content", "tesing error"))
- fmt.Println(coloredLog)
- }
- func ExampleColorLog() {
- com.ColorLog(fmt.Sprintf(
- "[WARN] This is a tesing log that should be colored, path( %s ),"+
- " highlight # %s #, error [ %s ].",
- "path to somewhere", "highlighted content", "tesing error"))
- }
- func ExampleExecCmd() {
- stdout, stderr, err := com.ExecCmd("go", "help", "get")
- fmt.Println(stdout, stderr, err)
- }
- func ExampleHtml2JS() {
- htm := "<div id=\"button\" class=\"btn\">Click me</div>\n\r"
- js := string(com.Html2JS([]byte(htm)))
- fmt.Println(js)
-
- }
- func ExampleGetGOPATHs() {
- gps := com.GetGOPATHs()
- fmt.Println(gps)
- }
- func ExampleGetSrcPath() {
- srcPath, err := com.GetSrcPath("notabug.org/makenotabuggreatagain/com")
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println(srcPath)
- }
- func ExampleHomeDir() {
- hd, err := com.HomeDir()
- fmt.Println(hd, err)
- }
- func ExampleIsFile() {
- if com.IsFile("file.go") {
- fmt.Println("file.go exists")
- return
- }
- fmt.Println("file.go is not a file or does not exist")
- }
- func ExampleIsExist() {
- if com.IsExist("file.go") {
- fmt.Println("file.go exists")
- return
- }
- fmt.Println("file.go does not exist")
- }
- func ExampleIsDir() {
- if com.IsDir("files") {
- fmt.Println("directory 'files' exists")
- return
- }
- fmt.Println("'files' is not a directory or does not exist")
- }
- func ExampleIsLetter() {
- fmt.Println(com.IsLetter('1'))
- fmt.Println(com.IsLetter('['))
- fmt.Println(com.IsLetter('a'))
- fmt.Println(com.IsLetter('Z'))
-
-
-
-
-
- }
-
- func ExampleHttpGet() ([]byte, error) {
- rc, err := com.HttpGet(&http.Client{}, "http://gowalker.org", nil)
- if err != nil {
- return nil, err
- }
- p, err := ioutil.ReadAll(rc)
- rc.Close()
- return p, err
- }
- func ExampleHttpGetBytes() ([]byte, error) {
- p, err := com.HttpGetBytes(&http.Client{}, "http://gowalker.org", nil)
- return p, err
- }
- func ExampleHttpGetJSON() interface{} {
- j := com.HttpGetJSON(&http.Client{}, "http://gowalker.org", nil)
- return j
- }
- type rawFile struct {
- name string
- rawURL string
- data []byte
- }
- func (rf *rawFile) Name() string {
- return rf.name
- }
- func (rf *rawFile) RawUrl() string {
- return rf.rawURL
- }
- func (rf *rawFile) Data() []byte {
- return rf.data
- }
- func (rf *rawFile) SetData(p []byte) {
- rf.data = p
- }
- func ExampleFetchFiles() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- files := []com.RawFile{
- &rawFile{rawURL: "http://example.com"},
- &rawFile{rawURL: "http://example.com/foo"},
- }
- err := com.FetchFiles(&http.Client{}, files, nil)
- fmt.Println(err, len(files[0].Data()), len(files[1].Data()))
- }
- func ExampleFetchFilesCurl() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- files := []com.RawFile{
- &rawFile{rawURL: "http://example.com"},
- &rawFile{rawURL: "http://example.com/foo"},
- }
- err := com.FetchFilesCurl(files)
- fmt.Println(err, len(files[0].Data()), len(files[1].Data()))
- }
- func ExampleIsEmail() {
- fmt.Println(com.IsEmail("test@example.com"))
- fmt.Println(com.IsEmail("@example.com"))
-
-
-
- }
- func ExampleIsUrl() {
- fmt.Println(com.IsUrl("http://example.com"))
- fmt.Println(com.IsUrl("http//example.com"))
-
-
-
- }
- func ExampleAppendStr() {
- s := []string{"a"}
- s = com.AppendStr(s, "a")
- s = com.AppendStr(s, "b")
- fmt.Println(s)
-
- }
|