github.com/schmorrison/Zoho@v1.1.4/books/books.go (about)

     1  package books
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  
     7  	zoho "github.com/schmorrison/Zoho"
     8  )
     9  
    10  // API is used for interacting with the Zoho Books API
    11  type API struct {
    12  	*zoho.Zoho
    13  	id string
    14  }
    15  
    16  // New returns a *books.API with the provided zoho.Zoho as an embedded field
    17  func New(z *zoho.Zoho) *API {
    18  	id := func() string {
    19  		var id []byte
    20  		keyspace := "abcdefghijklmnopqrutuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    21  		for i := 0; i < 25; i++ {
    22  			source := rand.NewSource(time.Now().UnixNano())
    23  			rnd := rand.New(source)
    24  			id = append(id, keyspace[rnd.Intn(len(keyspace))])
    25  		}
    26  		return string(id)
    27  	}()
    28  
    29  	return &API{
    30  		Zoho: z,
    31  		id:   id,
    32  	}
    33  }