-
Notifications
You must be signed in to change notification settings - Fork 0
/
goog.go
44 lines (35 loc) · 901 Bytes
/
goog.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
package goog
import (
"github.com/hiphoox/goog/rest"
l4g "code.google.com/p/log4go"
)
const (
CONNECT_URL = "/connect/"
HTTP_PREFIX = "http://"
)
type DataBase struct {
name string
server string
client *rest.Client
}
func Connect(server, database_name, login, password string) (DataBase, error) {
l4g.Trace("Inside Connect")
var db DataBase
// Create client
client, err := rest.New(HTTP_PREFIX + server)
if err == nil {
l4g.Trace("Getting token...")
client.SetBasicAuth(login, password)
err = client.GetHeaders(CONNECT_URL + database_name)
if err == nil {
l4g.Trace("Creating database structure...")
db = DataBase{ name: database_name,
server: server,
client: client}
}
}
return db, err
}
func (db *DataBase) GetToken() string {
return db.client.GetHeader("Set-Cookie")
}