func main() { apiKeyPtr := flag.String("api-key", "", "Telemetry API Key") boardNamePtr := flag.String("n", "", "Name of the board to create") boardPrefixPtr := flag.String("p", "", "Flow tag prefix") filePathPtr := flag.String("f", "", "Input file path") flag.Parse() apiKey := strings.TrimSpace(*apiKeyPtr) boardName := strings.TrimSpace(*boardNamePtr) boardPrefix := strings.TrimSpace(*boardPrefixPtr) filePath := strings.TrimSpace(*filePathPtr) if apiKey == "" { log.Fatal("The API Key is required") } if boardName == "" { log.Fatal("The board name is required") } if boardPrefix == "" { log.Fatal("The board prefix is required") } if filePath == "" { log.Fatal("The file path is required") } fileContents, err := ioutil.ReadFile(filePath) if err != nil { log.Fatal(err) } boardTemplate := &gotelemetry.ExportedBoard{} err = json.Unmarshal(fileContents, &boardTemplate) if err != nil { log.Fatal(err) } credentials, err := gotelemetry.NewCredentials(apiKey) if err != nil { log.Fatal(err) } board, err := gotelemetry.ImportBoard(credentials, boardName, boardPrefix, boardTemplate) if err != nil { log.Fatal(err) } log.Printf("Success: %v", board) }
// GetOrCreateBoard either creates a board based on an exported template, or retrieves it // if a board with the same name already exists. // // The template must be passed in JSON format as a string (you can use gotelemetry/boarddump to // generate a template based on an existing board). func (j *Job) GetOrCreateBoard(name, prefix string, templateSource string) (*gotelemetry.Board, error) { template := &gotelemetry.ExportedBoard{} err := json.Unmarshal([]byte(templateSource), &template) if err != nil { return nil, err } return gotelemetry.ImportBoard(j.credentials, name, prefix, template) }