Comment 10 for bug 1465724

Revision history for this message
Rick Spencer (rick-rickspencer3) wrote :

For what it is worth, if any cares, here is a smaller code listing that produces the error

package main

import (
 "fmt"
 "io/ioutil"
 "log"
 "os"
 "path/filepath"
 "time"
)
import "gopkg.in/yaml.v2"

var config Config

type Config struct {
 Duration string
}

func appDataPath() string {
 //use the full path to the app when in a snap package, but
 //for local development, assume that the app is run from bin/arch
 dir := os.Getenv("SNAP_APP_PATH")
 fmt.Println("app path ENV is " + dir)

 if dir == "" {
  fmt.Println("no snap app data path, guessing ../../")
  dir = "../../"
 }

 return dir
}

func initConfig() {
 //create a Config instance and fill it from the yaml file
 dir := appDataPath()

 yamlfilename := filepath.Join(dir, "cnf", "config.yaml")
 fmt.Println("Looking for yaml file at: " + yamlfilename)

 yamlFile, err := ioutil.ReadFile(yamlfilename)

 err = yaml.Unmarshal(yamlFile, &config)
 if err != nil {
  fmt.Println("failed to read config")
  log.Fatal(err)
 } else {
  fmt.Println("config created")
 }
}

func main() {
 fmt.Println("Uploader started")
 initConfig()
 s, err := time.ParseDuration(config.Duration)
 if err != nil {
  fmt.Println("failed to read seconds from config")
  log.Fatal(err)
 }
 ticker := time.NewTicker(s)
 for _ = range ticker.C {
  fmt.Println("tick")
 }