创建文件
package main
import (
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
fileName := "zdpgo_hdfs.txt"
content := []byte("Hello, world!")
// 创建文件
err := zdpgo_hdfs.CreateFile(host, port, fileName, content)
if err != nil {
panic(err)
}
}
向指定文件追加内容
package main
import (
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
fileName := "zdpgo_hdfs.txt"
content := []byte("\n\n11111 Hello, world!")
// 创建文件
err := zdpgo_hdfs.AppendFile(host, port, fileName, content)
if err != nil {
panic(err)
}
}
读取文件内容
package main
import (
"fmt"
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
fileName := "zdpgo_hdfs.txt"
// 创建文件
content, err := zdpgo_hdfs.ReadFile(host, port, fileName)
if err != nil {
panic(err)
}
fmt.Println(content)
}
创建文件夹
package main
import (
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
targetDir := "zdpgo_hdfs"
// 创建文件夹
err := zdpgo_hdfs.CreateDir(host, port, targetDir)
if err != nil {
panic(err)
}
}
重命名文件或文件夹
package main
import (
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
sourceDir := "zdpgo_hdfs"
targetDir := "/zdpgo_hdfs111"
// 创建文件夹
err := zdpgo_hdfs.Rename(host, port, sourceDir, targetDir)
if err != nil {
panic(err)
}
}
删除文件或文件夹
package main
import (
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
targetDir := "/zdpgo_hdfs111"
// 创建文件夹
err := zdpgo_hdfs.Delete(host, port, targetDir)
if err != nil {
panic(err)
}
}
查看文件或文件夹状态
package main
import (
"fmt"
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
targetPath := "zdpgo_hdfs.txt"
status, err := zdpgo_hdfs.Status(host, port, targetPath)
if err != nil {
panic(err)
}
fmt.Println(status)
}
查看指定目录文件列表
package main
import (
"fmt"
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
targetPath := "/"
files, err := zdpgo_hdfs.GetDirFiles(host, port, targetPath)
if err != nil {
panic(err)
}
fmt.Println(files)
}
获取文件信息
package main
import (
"fmt"
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
targetPath := "/zdpgo_hdfs.txt"
fileInfo, err := zdpgo_hdfs.GetFileCheckSum(host, port, targetPath)
if err != nil {
panic(err)
}
fmt.Println(fileInfo)
}
获取家目录
package main
import (
"fmt"
"zdpgo_hdfs"
)
func main() {
host := "localhost"
port := 9870
homeDir, err := zdpgo_hdfs.GetHomeDir(host, port)
if err != nil {
panic(err)
}
fmt.Println(homeDir)
}
领取专属 10元无门槛券
私享最新 技术干货