-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
54 lines (47 loc) · 1.47 KB
/
main.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
/*
* license/metered-non-persistent-cache/main.go:
* Illustrates how to load a metered license API key and set the persistent cache.
* Free api keys can be obtained at: https://cloud.unidoc.io
*
* Run as: go run main.go
*/
package main
import (
"fmt"
"github.com/unidoc/unioffice/common/license"
)
func init() {
// To get your free API key for metered license, sign up on: https://cloud.unidoc.io
// Make sure to be using UniOffice v1.9.0 or newer for Metered API key support.
err := license.SetMeteredKey(`my metered api key goes here`)
if err != nil {
fmt.Printf("ERROR: Failed to set metered key: %v\n", err)
fmt.Printf("Make sure to get a valid key from https://cloud.unidoc.io\n")
panic(err)
}
// Set cache storage for API Key usages, the default is `true` set to `false`
// for instance that not having persistent disk storage location.
license.SetMeteredKeyPersistentCache(false)
}
func main() {
lk := license.GetLicenseKey()
if lk == nil {
fmt.Printf("Failed retrieving license key")
return
}
fmt.Printf("License: %s\n", lk.ToString())
// GetMeteredState freshly checks the state, contacting the licensing server.
state, err := license.GetMeteredState()
if err != nil {
fmt.Printf("ERROR getting metered state: %+v\n", err)
panic(err)
}
fmt.Printf("State: %+v\n", state)
if state.OK {
fmt.Printf("State is OK\n")
} else {
fmt.Printf("State is not OK\n")
}
fmt.Printf("Credits: %v\n", state.Credits)
fmt.Printf("Used credits: %v\n", state.Used)
}