无聊尝试一下golang连接hdfs,写了个hello world
golang包地址
https://github.com/vladimirvivien/gowfs
安装
gogetgithub.com/vladimirvivien/gowfs
分别是
hsdfs-site.xml 里的
dfs.webhdfs.enabled
<property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property>
core-site.xml里的
hadoop.http.staticuser.user
<property> <name>hadoop.http.staticuser.user</name> <value>hadoop</value> </property>
简单的例子
packagemain import( "fmt" "log" "github.com/vladimirvivien/gowfs" ) funcmain(){ fs,err:=gowfs.NewFileSystem(gowfs.Configuration{Addr:"localhost:50070",User:"hadoop"}) iferr!=nil{ log.Fatal(err) } checksum,err:=fs.GetFileChecksum(gowfs.Path{Name:"/user/kafka/hello.txt"}) iferr!=nil{ log.Fatal(err) } fmt.Println(checksum) createTestDir(fs,"/user/kafka/hello1.txt") } funccreateTestDir(fs*gowfs.FileSystem,hdfsPathstring){ path:=gowfs.Path{Name:hdfsPath} ok,err:=fs.MkDirs(path,0744) iferr!=nil||!ok{ log.Fatal("Unabletocreatetestdirectory",hdfsPath,":",err) } log.Println("HDFSPath",path.Name,"created.") }原文链接:https://www.f2er.com/go/190888.html