Debian Codegraph @

localservices/localservice.go

raw symbols SCIP
1 //
2 // gosdc - Go library to interact with the Joyent CloudAPI
3 //
4 // Double testing service
5 //
6 // Copyright (c) Joyent Inc.
7 //
8
9 package localservices
10
11 import (
12 "crypto/rand"
13 "encoding/hex"
14 "fmt"
15 "io"
16
17 "github.com/joyent/gosdc/localservices/hook"
18 "github.com/julienschmidt/httprouter"
19 )
20
21 // An HttpService provides the HTTP API for a service double.
22 type HttpService interface {
23 SetupHTTP(mux *httprouter.Router)
24 }
25
26 // A ServiceInstance is an Joyent Cloud service.
27 type ServiceInstance struct {
28 hook.TestService
29 Scheme string
30 Hostname string
31 UserAccount string
32 }
33
34 // NewUUID generates a random UUID according to RFC 4122
35 func NewUUID() (string, error) {
36 uuid := make([]byte, 16)
37 n, err := io.ReadFull(rand.Reader, uuid)
38 if n != len(uuid) || err != nil {
39 return "", err
40 }
41 uuid[8] = uuid[8]&^0xc0 | 0x80
42 uuid[6] = uuid[6]&^0xf0 | 0x40
43 return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
44 }
45
46 // NewMAC generates a new fake MAC address
47 func NewMAC() (string, error) {
48 mac := make([]byte, 6)
49 n, err := io.ReadFull(rand.Reader, mac)
50 if n != len(mac) || err != nil {
51 return "", err
52 }
53 e := hex.EncodeToString(mac)
54
55 return fmt.Sprintf("%s:%s:%s:%s:%s:%s", e[0:2], e[2:4], e[4:6], e[6:8], e[8:10], e[10:12]), nil
56 }