Exemplo n.º 1
0
/*
	test reading only as strings
*/
func TestStrings(t *testing.T) {
	var (
		my_map map[string]map[string]*string
		dup    string
	)

	my_map = make(map[string]map[string]*string)
	my_map["default"] = make(map[string]*string)
	dup = "should be overlaid by config file info" // should be overridden
	my_map["default"]["ffoo"] = &dup
	dup = "initial value, should exist after read"
	my_map["default"]["init-val"] = &dup

	fmt.Fprintf(os.Stderr, ">>>>> parsing\n")
	sects, err := config.Parse2strs(my_map, "test.cfg")

	if err != nil {
		fmt.Fprintf(os.Stderr, "parsing config file failed: %s\n", err)
		t.Fail()
		return
	}

	for sname, smap := range sects {
		fmt.Fprintf(os.Stderr, "section: (%s) has %d items\n", sname, len(smap))
		for key, value := range smap {
			fmt.Fprintf(os.Stderr, "\t%s = (%s)\n", key, *value)
		}
	}

	smap := sects["default"] // can be referenced two different ways
	fmt.Fprintf(os.Stderr, "qfoo=== (%s)\n", *smap["qfoo"])
	fmt.Fprintf(os.Stderr, "ffoo=== (%s)\n", *smap["ffoo"])
	fmt.Fprintf(os.Stderr, "ffoo=== (%s)\n", *sects["default"]["ffoo"])
}
Exemplo n.º 2
0
/*
	Sets up the global variables needed by the whole package. This should be invoked by the
	main tegu function (main/tegu.go).

	CAUTION:  this is not implemented as an init() function as we must pass information from the
			main to here.
*/
func Initialise(cfg_fname *string, ver *string, nwch chan *ipc.Chmsg, rmch chan *ipc.Chmsg, rmluch chan *ipc.Chmsg, osifch chan *ipc.Chmsg, fqch chan *ipc.Chmsg, amch chan *ipc.Chmsg) (err error) {
	err = nil

	def_log_dir := "."
	log_dir := &empty_str

	nw_ch = nwch
	rmgr_ch = rmch
	rmgrlu_ch = rmluch
	osif_ch = osifch
	fq_ch = fqch
	am_ch = amch

	if ver != nil {
		version = *ver
	}

	tegu_sheep = bleater.Mk_bleater(1, os.Stderr) // the main (parent) bleater used by libraries and as master 'volume' control
	tegu_sheep.Set_prefix("tegu")

	pid = os.Getpid() // used to keep reservation names unique across invocations

	tklr = ipc.Mk_tickler(30)                   // shouldn't need more than 30 different tickle spots
	tklr.Add_spot(2, rmgr_ch, REQ_NOOP, nil, 1) // a quick burst tickle to prevent a long block if the first goroutine to schedule a tickle schedules a long wait

	if cfg_fname != nil {
		cfg_data, err = config.Parse2strs(nil, *cfg_fname) // capture config data as strings -- referenced as cfg_data["sect"]["key"]
		if err != nil {
			err = fmt.Errorf("unable to parse config file %s: %s", *cfg_fname, err)
			return
		}

		if p := cfg_data["default"]["shell"]; p != nil {
			shell_cmd = *p
		}
		if p := cfg_data["default"]["verbose"]; p != nil {
			tegu_sheep.Set_level(uint(clike.Atoi(*p)))
		}
		if log_dir = cfg_data["default"]["log_dir"]; log_dir == nil {
			log_dir = &def_log_dir
		}
	} else {
		cfg_data = nil
	}

	tegu_sheep.Add_child(gizmos.Get_sheep()) // since we don't directly initialise the gizmo environment we ask for its sheep
	if *log_dir != "stderr" {                // if overriden in config
		lfn := tegu_sheep.Mk_logfile_nm(log_dir, 86400)
		tegu_sheep.Baa(1, "switching to log file: %s", *lfn)
		tegu_sheep.Append_target(*lfn, false)      // switch bleaters to the log file rather than stderr
		go tegu_sheep.Sheep_herder(log_dir, 86400) // start the function that will roll the log now and again
	}

	return
}