6.2. Sharing a file with another userΒΆ
Your client application must allow users to share files (see Sharing and Revoking).
Here is an example code snippet that shows Alice sharing a file with Bob.
package main
import "github.com/cs161-staff/project2-starter-code/client"
func main() {
aliceUsername := "user_alice"
alice, _ := client.InitUser(aliceUsername, "password1")
bobUsername := "user_bob"
bob, _ := client.InitUser(bobUsername, "password2")
aliceContent := []byte("content")
filenameInAliceNamespace := "file1.txt"
alice.StoreFile(filenameInAliceNamespace, aliceContent)
invitationPtr, err := alice.CreateInvitation(filenameInAliceNamespace, bobUsername)
if err != nil {
panic(err)
}
filenameInBobNamespace := "from_alice.txt"
bob.AcceptInvitation(aliceUsername, invitationPtr, filenameInBobNamespace)
bobContent, err := bob.LoadFile(filenameInBobNamespace)
if err != nil {
panic(err)
}
// aliceContent should be equivalent to bobContent
}