Add examples

Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com>
This commit is contained in:
0x6f736f646f
2022-02-18 08:46:48 +03:00
parent 531847fa69
commit 19a15415f5
3 changed files with 71 additions and 9 deletions
+62
View File
@@ -0,0 +1,62 @@
package main
import (
"encoding/json"
"fmt"
"os"
"time"
mem "github.com/0x6f736f646f/memfault-go/pkg"
)
var (
username = os.Getenv("MEMFAULT_USERNAME")
password = os.Getenv("MEMFAULT_PASSWORD")
)
func main() {
creds := mem.Credentials{
Email: username,
Password: password,
}
d, _ := time.ParseDuration("30s")
conf := mem.Config{
APIURL: "https://api.memfault.com",
Credentials: creds,
MaxIdleConns: 10,
IdleConnTimeout: d,
}
memfault := mem.NewSDK(conf)
project := mem.Project{
Name: "smartsink",
Slug: "smartsink",
Os: "FreeRTOS",
Platform: "nRF52",
}
cohort := mem.Cohort{
Name: "demo5",
Slug: "demo5",
}
response1, err := memfault.CreateCohort(project, cohort)
if err != nil {
fmt.Println(err)
} else {
b, err := json.MarshalIndent(response1, "", " ")
if err != nil {
fmt.Println(err)
}
fmt.Print(string(b))
}
response2, err := memfault.ListCohorts(project)
if err != nil {
fmt.Println(err)
} else {
b, err := json.MarshalIndent(response2, "", " ")
if err != nil {
fmt.Println(err)
}
fmt.Print(string(b))
}
}
+8 -8
View File
@@ -5,7 +5,7 @@ import (
"os"
"time"
mem "github.com/0x6f736f646f/memfault-go/pkg/memfault"
mem "github.com/0x6f736f646f/memfault-go/pkg"
)
var (
@@ -28,8 +28,8 @@ func main() {
memfault := mem.NewSDK(conf)
payload := mem.Project{
Name: "SmartSdinkamakeabc",
Slug: "smartsdinkmskeabc",
Name: "smartsink",
Slug: "smartsink",
Os: "FreeRTOS",
Platform: "nRF52",
}
@@ -70,9 +70,9 @@ func main() {
fmt.Println(response7)
response5, err := memfault.DeleteProject(payload)
if err != nil {
fmt.Println(err)
}
fmt.Println(response5)
// response5, err := memfault.DeleteProject(payload)
// if err != nil {
// fmt.Println(err)
// }
// fmt.Println(response5)
}
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"os"
"time"
mem "github.com/0x6f736f646f/memfault-go/pkg/memfault"
mem "github.com/0x6f736f646f/memfault-go/pkg"
)
var (