-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
78 lines (62 loc) · 1.65 KB
/
app.go
File metadata and controls
78 lines (62 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
A trivial application to illustrate how the dfslib library can be used
from an application in assignment 2 for UBC CS 416 2017W2.
Usage:
go run app.go
*/
package main
// Expects dfslib.go to be in the ./dfslib/ dir, relative to
// this app.go file
import "./dfslib"
import "fmt"
import "os"
func main() {
serverAddr := "0.0.0.0:8080"
localIP := "0.0.0.0"
localPath := "/tmp/dfs-dev/"
// Connect to DFS.
_, err := dfslib.MountDFS(serverAddr, localIP, localPath)
if checkError(err) != nil {
fmt.Println(err)
return
}
// // Close the DFS on exit.
// // Defers are really cool, check out: https://blog.golang.org/defer-panic-and-recover
// defer dfs.UMountDFS()
// // Check if hello.txt file exists in the global DFS.
// exists, err := dfs.GlobalFileExists("helloworld")
// if checkError(err) != nil {
// return
// }
// if exists {
// fmt.Println("File already exists, mission accomplished")
// return
// }
// // Open the file (and create it if it does not exist) for writing.
// f, err := dfs.Open("helloworld", dfslib.WRITE)
// if checkError(err) != nil {
// return
// }
// // Close the file on exit.
// defer f.Close()
// // Create a chunk with a string message.
// var chunk dfslib.Chunk
// const str = "Hello friends!"
// copy(chunk[:], str)
// // Write the 0th chunk of the file.
// err = f.Write(0, &chunk)
// if checkError(err) != nil {
// return
// }
// // Read the 0th chunk of the file.
// err = f.Read(0, &chunk)
// checkError(err)
}
// If error is non-nil, print it out and return it.
func checkError(err error) error {
if err != nil {
fmt.Fprintf(os.Stderr, "Error ", err.Error())
return err
}
return nil
}