~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/joyent/gosdc/localservices/localservice.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// gosdc - Go library to interact with the Joyent CloudAPI
 
3
//
 
4
// Double testing service
 
5
//
 
6
// Copyright (c) 2013 Joyent Inc.
 
7
//
 
8
// Written by Daniele Stroppa <daniele.stroppa@joyent.com>
 
9
//
 
10
 
 
11
package localservices
 
12
 
 
13
import (
 
14
        "crypto/rand"
 
15
        "fmt"
 
16
        "io"
 
17
        "net/http"
 
18
 
 
19
        "github.com/joyent/gosdc/localservices/hook"
 
20
)
 
21
 
 
22
// An HttpService provides the HTTP API for a service double.
 
23
type HttpService interface {
 
24
        SetupHTTP(mux *http.ServeMux)
 
25
}
 
26
 
 
27
// A ServiceInstance is an Joyent Cloud service.
 
28
type ServiceInstance struct {
 
29
        hook.TestService
 
30
        Scheme      string
 
31
        Hostname    string
 
32
        UserAccount string
 
33
}
 
34
 
 
35
// NewUUID generates a random UUID according to RFC 4122
 
36
func NewUUID() (string, error) {
 
37
        uuid := make([]byte, 16)
 
38
        n, err := io.ReadFull(rand.Reader, uuid)
 
39
        if n != len(uuid) || err != nil {
 
40
                return "", err
 
41
        }
 
42
        uuid[8] = uuid[8]&^0xc0 | 0x80
 
43
        uuid[6] = uuid[6]&^0xf0 | 0x40
 
44
        return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
 
45
}