This repository has been archived by the owner on Jan 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bots.go
61 lines (53 loc) · 1.72 KB
/
bots.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
56
57
58
59
60
61
// Package bots contains shared data between the host and plugins.
package bots
import (
"github.com/ipfs/go-datastore"
)
// HostConfig is pulled from the bot config file
type HostConfig struct {
Name string
ID string
ReleaseVersion int
ReleaseHash string
Params map[string]string
}
// ClientConfig contain all the services and config passed by the host node
type ClientConfig struct {
Store DatastoreWithoutQuery
Ipfs Ipfs
Params map[string]string
}
// Response is the response for each request to a Bot
type Response struct {
Status int32
Body []byte
ContentType string
}
// Read is the read-side of the Datastore interface minus Query.
type DatastoreWithoutQuery interface {
// See datastore Get
Get(key datastore.Key) (value []byte, err error)
// See datastore Has
Has(key datastore.Key) (exists bool, err error)
// See datastore GetSize
GetSize(key datastore.Key) (size int, err error)
// See datastore Put
Put(key datastore.Key, value []byte) error
// See datastore Delete
Delete(key datastore.Key) error
// See datastore Close
Close() error
// TODO: Implement query/result in Protobuf/rpc and go to complete Datastore
}
// Ipfs is an interface to the gateway method to fetch + decrypt content
type Ipfs interface {
Get(path string, key string) (data []byte, err error)
Add(data []byte, encrypt bool) (hash string, key string, err error)
}
// Service defines the methods served by any bot
type Service interface {
Post(data []byte, body []byte, shared ClientConfig) (Response, error)
Get(data []byte, shared ClientConfig) (Response, error)
Put(data []byte, body []byte, shared ClientConfig) (Response, error)
Delete(data []byte, shared ClientConfig) (Response, error)
}