ftp示例
package main
import (
"flag"
"fmt"
"log"
"time"
expect "github.com/google/goexpect"
"github.com/google/goterm/term"
)
const (
timeout = 10 * time.Minute
)
var (
addr = flag.String("address", "", "address of telnet server")
user = flag.String("user", "", "username to use")
pass = flag.String("pass", "", "password to use")
)
func main() {
flag.Parse()
fmt.Println(term.Bluef("Ftp 1 example"))
e, _, err := expect.Spawn(fmt.Sprintf("ftp %s", *addr), -1)
if err != nil {
log.Fatal(err)
}
defer e.Close()
e.ExpectBatch([]expect.Batcher{
&expect.BExp{R: "username:"},
&expect.BSnd{S: *user + "\n"},
&expect.BExp{R: "password:"},
&expect.BSnd{S: *pass + "\n"},
&expect.BExp{R: "ftp>"},
&expect.BSnd{S: "bin\n"},
&expect.BExp{R: "ftp>"},
&expect.BSnd{S: "prompt\n"},
&expect.BExp{R: "ftp>"},
&expect.BSnd{S: "mget *\n"},
&expect.BExp{R: "ftp>"},
&expect.BSnd{S: "bye\n"},
}, timeout)
fmt.Println(term.Greenf("All done"))
}
go mod 基础知识
go mod init gitee.com/wangwei830/test #初始化
go get -d github.com/example/b #下载更新指定库,只跟新go.mod中的依赖,轻量级
go get -u github.com/example/b #下载更新指定库与依赖它的库,全量
go mod download #下载go.mod文件中的依赖连库
go mod tidy #整理并跟新go.mod依赖信息
go env set GOPROXY=https://mirrors.aliyun.com/goproxy,direct #阿里云
go env set GOPROXY=https://goproxy.cn,direct #七牛云
go env set GOPROXY=https://goproxy.io,direct #全球代理
我的golang环境
重点:
set GOPATH=D:\gopath1.18
set GOMODCACHE=D:\gopath1.18\pkg\mod
set GOPROXY=https://goproxy.cn,direct
#set GOHOSTOS="linux"
set GOHOSTARCH=amd64
set GOHOSTOS=windows
全貌:
D:\gopath1.18\src\testgo>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Lenovo\AppData\Local\go-build
set GOENV=C:\Users\Lenovo\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\gopath1.18\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\gopath1.18
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=D:\go1.18
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\go1.18\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\gopath1.18\src\testgo\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Lenovo\AppData\Local\Temp\go-build1100672428=/tmp/go-build -gno-record-gcc-switches
D:\gopath1.18\src\testgo>