-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_server.go
55 lines (46 loc) · 1.36 KB
/
session_server.go
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
package gist9p
import (
"errors"
"github.com/docker/go-p9p"
"github.com/google/go-github/github"
"golang.org/x/net/context"
"log"
)
type GistSession struct {
client *github.Client
fidMap map[p9p.Fid]Node
}
func NewGistSession(token string) *GistSession {
var gs GistSession
gs.client = githubClientFromToken(token)
gs.fidMap = make(map[p9p.Fid]Node)
return &gs
}
func (gs *GistSession) Auth(ctx context.Context, afid p9p.Fid, uname, aname string) (p9p.Qid, error) {
return p9p.Qid{}, errors.New("no auth")
}
func (gs *GistSession) Attach(ctx context.Context, fid, afid p9p.Fid, uname, aname string) (p9p.Qid, error) {
log.Println("attaching")
rootNode := NewRootNode(gs.client)
gs.fidMap[fid] = rootNode
return rootNode.qid, nil
}
func (gs *GistSession) Clunk(ctx context.Context, fid p9p.Fid) error {
log.Println("clunking fid", fid)
if file, ok := gs.fidMap[fid]; ok {
delete(gs.fidMap, fid)
err := clunk(file)
return err
} else {
return errors.New("don't know that fid")
}
}
func (gs *GistSession) Remove(ctx context.Context, fid p9p.Fid) error {
return errors.New("cant remove yet")
}
func (gs *GistSession) Create(ctx context.Context, parent p9p.Fid, name string, perm uint32, mode p9p.Flag) (p9p.Qid, uint32, error) {
return p9p.Qid{}, 0, errors.New("cant create yet")
}
func (gs *GistSession) Version() (int, string) {
return 2048, "9p2000"
}