Golang Panicln示例

说明

golang panicln示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: log

示例#1
文件: statsdtop.go 项目: kgilmer/statsdtop

func main() {
	flag.Parse()

	if *showVersion {
		fmt.Printf("statsdaemon v%s (built w/%s)\n", VERSION, runtime.Version())
		return
	}

	signalchan = make(chan os.Signal, 1)
	signal.Notify(signalchan, syscall.SIGTERM)
	*persistCountKeys = -1 * (*persistCountKeys)

	go udpListener()

	g := gocui.NewGui()
	if err := g.Init(); err != nil {
		log.Panicln(err)
	}
	defer g.Close()

	g.SetLayout(layout)
	if err := g.SetKeybinding("", gocui.KeyCtrlC, 0, quit); err != nil {
		log.Panicln(err)
	}

	go updateViews(g)
	go monitor()

	err := g.MainLoop()
	if err != nil && err != gocui.ErrorQuit {
		log.Panicln(err)
	}
}

示例#2
文件: DataLoader.go 项目: sinni800/sgemu

func LoadBinds(Done chan bool) {
	defer func() {
		if x := recover(); x != nil {
			log.Printf("%v\n%s", x, C.PanicPath())
			Done <- false
		} else {
			Done <- true
		}
	}()
	f, e := os.Open(bindsPath)
	if e != nil {
		log.Panicln(e)
	}

	defer f.Close()

	bf := &BindingFile{}

	e = xml.NewDecoder(f).Decode(bf)
	if e != nil {
		log.Panicln(e)
	}

	for _, group := range bf.Groups {
		Binds[group.UID] = group
	}
}

示例#3
文件: DataLoader.go 项目: sinni800/sgemu

func LoadItems(Done chan bool) {
	defer func() {
		if x := recover(); x != nil {
			log.Printf("%v\n%s", x, C.PanicPath())
			Done <- false
		} else {
			Done <- true
		}
	}()

	f, e := os.Open(itemPath)
	if e != nil {
		log.Panicln(e)
	}

	defer f.Close()

	type xmlitems struct {
		XMLName       xml.Name         `xml:"Items"`
		ItemDataGroup []*ItemDataGroup `xml:"ItemGroup"`
	}

	items := new(xmlitems)
	e = xml.NewDecoder(f).Decode(items)
	if e != nil {
		log.Panicln(e)
	}

	for _, ig := range items.ItemDataGroup {
		ItemsByGroup[ig.GID] = ig.ItemData
		for _, it := range ig.ItemData {
			Items[it.ID] = it
		}
	}
}

示例#4
文件: bufs.go 项目: jmptrader/gocui

func main() {
	g := gocui.NewGui()
	if err := g.Init(); err != nil {
		log.Panicln(err)
	}

	g.SetLayout(layout)
	if err := g.SetKeybinding("main", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
		log.Panicln(err)
	}
	g.SetLayout(layout)
	if err := g.SetKeybinding("main", gocui.KeyCtrlI, gocui.ModNone, overwrite); err != nil {
		log.Panicln(err)
	}
	g.Cursor = true
	g.Mouse = true

	if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
		log.Panicln(err)
	}

	g.Close()

	fmt.Printf("VBUF:\n%s\n", vbuf)
	fmt.Printf("BUF:\n%s\n", buf)
}

示例#5
文件: main.go 项目: ntk1000/go-web-book-playground

func main() {
	cmdChain[0].Stdin = os.Stdin
	cmdChain[len(cmdChain)-1].Stdout = os.Stdout

	for i := 0; i < len(cmdChain)-1; i++ {
		thisCmd := cmdChain[i]
		nextCmd := cmdChain[i+1]
		strout, err := thisCmd.StdoutPipe()
		if err != nil {
			log.Panicln(err)
		}
		nextCmd.Stdin = stdout
	}

	for _, cmd := range cmdChain {
		if err := cmd.Start(); err != nil {
			log.Panicln(err)
		} else {
			defer cmd.Process.Kill()
		}
	}

	for _, cmd := range cmdChain {
		if _, err := cmd.Wait(); err != nil {
			log.Panicln(err)
		}
	}
}

示例#6
文件: resque.go 项目: perplexes/resque-client.go

func NewClient(cspec *ClientSpec) Client {
	if cspec == nil {
		cspec = DefaultSpec()
	}

	cspec.Queue = fmt.Sprintf("resque:queue:%s", cspec.Queue)

	client, e := redis.Dial("tcp", cspec.RedisLocation)
	if e != nil {
		log.Panicln("failed to create the client", e)
	}

	// Select their database.
	client.Send("SELECT", cspec.RedisDatabase)
	client.Flush()
	ok, receiveE := client.Receive()
	if ok != "OK" || receiveE != nil {
		log.Panicln("Unable to switch database.", receiveE)
	}

	return Client{
		cspec,
		&client,
	}
}

示例#7
文件: gui.go 项目: robert-butts/slackterm

func guiUpdater(g *gocui.Gui,
	updateMsgsChan <-chan string,
	getUserNameChan chan<- UserNameRequest,
	getChannelNameChan chan<- ChannelNameRequest,
	getMessagesChan chan<- MessageRequest,
	slackToken string) {
	for {
		log.Println("guiUpdater listening")
		select {
		case channelId := <-updateMsgsChan:
			log.Println("guiUpdater not listening")
			log.Println("gui updater got " + channelId)
			channelName := GetChannelName(channelId, getChannelNameChan)
			log.Println("guiupdater name " + channelName)
			selectedChannelName, err := getSelectedChannelName(g)
			log.Println("guiupdater selectedname " + selectedChannelName)
			if err != nil {
				log.Panicln(err)
			}
			if channelName != selectedChannelName {
				log.Println("guiupdater continuing")
				continue
			}
			log.Println("guiupdater populating messages")
			err = populateMessages(g, slackToken, channelId, getUserNameChan, getMessagesChan)
			log.Println("guiupdater populated msgs")
			if err != nil {
				log.Panicln(err)
			}
		}
	}
}

示例#8
文件: router_test.go 项目: snorochevskiy/jutra

func TestRoute(t *testing.T) {

	expectedHandler1 := func(context *HttpContext) { log.Panicln("1") }
	expectedRefHandler1 := reflect.ValueOf(expectedHandler1)

	expectedHandler2 := func(context *HttpContext) { log.Panicln("2") }
	expectedRefHandler2 := reflect.ValueOf(expectedHandler2)

	rh := RoutedHandler{}
	rh.AddRoute("/", expectedHandler1)
	rh.AddRoute("/project/:projectId", expectedHandler2)

	route1 := rh.FindMatchingRoute("/")
	reflectHandler1 := reflect.ValueOf(route1.Handler)
	if reflectHandler1.Pointer() != expectedRefHandler1.Pointer() {
		t.Error("Can't find proper function for URL /")
	}

	route2 := rh.FindMatchingRoute("/project/1")
	reflectHandler2 := reflect.ValueOf(route2.Handler)
	if reflectHandler2.Pointer() != expectedRefHandler2.Pointer() {
		t.Error("Can't find proper function for URL /project/1")
	}
	projectId := route2.PathParams["projectId"]
	if projectId != "1" {
		t.Error("Path param should be '1'")
	}

}

示例#9
文件: edit.go 项目: YouROK/GoProjectManager

func main() {
	var err error

	proj, err = project.OpenProject("testprj/test.gop")
	if err != nil {
		log.Println(err)
		return
	}
	codecomplete.Init(proj)

	g := gocui.NewGui()
	if err := g.Init(); err != nil {
		log.Panicln(err)
	}
	defer g.Close()

	g.SetLayout(layout)
	if err := keybindings(g); err != nil {
		log.Panicln(err)
	}
	g.SelBgColor = gocui.ColorGreen
	g.SelFgColor = gocui.ColorBlack
	g.ShowCursor = true

	err = g.MainLoop()
	if err != nil && err != gocui.Quit {
		log.Panicln(err)
	}
}

示例#10
文件: godis_test.go 项目: yuya008/godis

func (req *Req) request(cmd uint8, args ...string) {
	buffer := bytes.NewBuffer(nil)
	err := binary.Write(buffer, binary.BigEndian, &cmd)
	if err != nil {
		log.Panicln(err)
	}
	if len(args) == 0 || args[0] == "" {
		req.conn.Write(buffer.Bytes())
		return
	}
	var paraN uint16 = uint16(len(args))
	err = binary.Write(buffer, binary.BigEndian, ¶N)
	if err != nil {
		log.Panicln(err)
	}
	for i := range args {
		var p1 uint64 = uint64(len(args[i]))
		err = binary.Write(buffer, binary.BigEndian, &p1)
		if err != nil {
			log.Fatalln(err)
		}
		buffer.WriteString(args[i])
	}
	req.conn.Write(buffer.Bytes())
}

示例#11
文件: download.go 项目: upccup/cuplearn

func main() {
	client, err := docker.NewVersionedClient("unix:///var/run/docker.sock", "1.17")

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fi, err := os.OpenFile("/data/test", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0420)
	if err != nil {
		log.Panicln(err)
	}

	cpOptions := docker.CopyFromContainerOptions{
		OutputStream: fi,
		Container:    "omega-abc",
		Resource:     "/data/test/",
	}

	err = client.CopyFromContainer(cpOptions)
	if err != nil {
		log.Println("copy failed")
		log.Panicln(err)
	}

	options := docker.DownloadFromContainerOptions{
		OutputStream: fi,
		Path:         "/data/test/",
	}

	err = client.DownloadFromContainer("omega-abc", options)
	if err != nil {
		log.Panicln(err)
	}
}

示例#12
文件: main.go 项目: JeremyOT/harborisland

func main() {
	var config struct {
		pollInterval time.Duration
		taskDef      string
		workDir      string
	}
	argTask := &task.Task{}
	flag.DurationVar(&config.pollInterval, "poll-interval", time.Minute, "The frequency with which to poll registered tasks for updates.")
	flag.StringVar(&config.taskDef, "task-def", "", "The path to a JSON file containing task definitions.")
	flag.StringVar(&config.workDir, "work-dir", "", "The path to a directory to use as the build directory.")
	structflag.StructToFlags("task", argTask)
	flag.Parse()
	taskMon, err := monitor.New(config.pollInterval, config.workDir)
	if err != nil {
		log.Panicln(err)
	}
	if argTask.ImageName != "" {
		taskMon.AddTask(argTask)
	}
	if config.taskDef != "" {
		tasks, err := LoadTasks(config.taskDef)
		if err != nil {
			log.Panicln(err)
		}
		for _, task := range tasks.Tasks {
			if task.Registry == "" {
				task.Registry = tasks.Registry
			}
			taskMon.AddTask(task)
		}
	}
	taskMon.Start()
	taskMon.Wait()
}

示例#13
文件: tool_sql_user.go 项目: phicuong08/ChineseChessCC

func (pstUserInfo *SqlUserInfo) getUserInfo(iUid int) {
	//检查数据库已初始化
	if nil == g_db {
		log.Panicln("database error: no init")
		return
	}

	//按照uid查询用户信息
	rows := g_db.QueryRow("select username, last_login, general_score, general_times from t_user where uid=?", iUid)
	var tmpName string
	var tmpLastLogin string
	var tmpScore int64
	var tmpTimes int
	err := rows.Scan(&tmpName, &tmpLastLogin, &tmpScore, &tmpTimes)
	if nil != err {
		log.Panicln("database error: select row ->", err)
		return
	}

	pstUserInfo.iUid = iUid
	pstUserInfo.name = tmpName
	pstUserInfo.last_login = tmpLastLogin
	pstUserInfo.general_score = tmpScore
	pstUserInfo.general_times = tmpTimes

	return
}

示例#14
文件: main.go 项目: oywc410/MYPG

//命令行操作
func main() {
	//指定各个程序的输入输出流
	cmdChain[0].Stdin = os.Stdin
	cmdChain[len(cmdChain)-1].Stdout = os.Stdout

	for i := 0; i < len(cmdChain)-1; i++ {
		thisCmd := cmdChain[i]
		nextCmd := cmdChain[i+1]
		stdout, err := thisCmd.StdoutPipe()
		if err != nil {
			log.Panicln(err)
		}
		nextCmd.Stdin = stdout
	}

	//运行程序
	//cmd.Start 非阻塞形式运行
	//cmd.Run 阻塞好形式运行
	for _, cmd := range cmdChain {
		if err := cmd.Start(); err != nil {
			log.Panicln(err)
		} else {
			defer cmd.Process.Kill()
		}
	}

	//cmd.Wait 阻塞等待运行结束
	for _, cmd := range cmdChain {
		if err := cmd.Wait(); err != nil {
			log.Panicln(err)
		}
	}
}

示例#15
文件: mapper.go 项目: ioriiod0/pratice

func mapper(id int, in io.Reader, outs []io.Writer, signals chan int) {

	defer func() {
		if err := recover(); err != nil {
			log.Println(err)
		}
		signals <- id
	}()

	rd := bufio.NewReader(in)
	size := len(outs)
	wds := make([]*bufio.Writer, size, size)
	for i, out := range outs {
		wds[i] = bufio.NewWriter(out)
	}

	for {
		if line, err := rd.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				log.Panicln(err)
			}
		} else {
			index := crc32.ChecksumIEEE([]byte(line)) % uint32(size) //hash
			if _, err := wds[index].WriteString(line); err != nil {
				log.Panicln(err)
			}
		}
	}

}

示例#16
文件: main.go 项目: ifo/goall

func main() {
	templatesDir := flag.String("templates-dir", "./_templates", "template directory")
	outputDir := flag.String("site", "./_site", "directory containing output")

	// setup
	flag.Parse()
	goalls.SetupTemplates(*templatesDir)
	errClean := goalls.CleanDir(*outputDir)
	if errClean != nil {
		log.Panicln(errClean)
	}

	// ensure example/site directory exists
	err := os.MkdirAll("./_site/posts", 0755)
	if err != nil {
		log.Printf("Warn: %v\n", err)
	}

	errIndex := CreateIndexPage(".", "./_posts")
	if errIndex != nil {
		log.Panicln("Could not assemble index page", errIndex)
	}

	CreatePosts("./_posts", "./_site/posts")
}

示例#17
文件: strato-temp.go 项目: stratoberry/strato-temp

func main() {
	flag.Parse()

	var dev *bmp085.Device
	var err error

	if dev, err = bmp085.Init(0x77, 1, bmp085.MODE_STANDARD); err != nil {
		log.Panicln("Failed to init device", err)
	}

	f, err := os.OpenFile(*outFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
	if err != nil {
		log.Panicln("Failed to open output file", err)
	}
	defer f.Close()

	conn, _ := net.Dial("udp", fmt.Sprintf("255.255.255.255:%d", *udpPort))
	defer conn.Close()

	t := time.Tick((*updateFreq) * time.Second)
	for now := range t {
		if temp, pressure, alt, err := dev.GetData(); err != nil {
			log.Panicln("Failed to get data from the device", err)
		} else {
			stanza := fmt.Sprintf("%d;%.2f;%.2f;%.2f\n", now.Unix()-EPOCH, temp, float64(pressure)/100, alt)

			f.WriteString(stanza)
			conn.Write([]byte(stanza))
		}
	}
}

示例#18
文件: ws_client.go 项目: henrikhodne/hustle

func newClient(ws *websocket.Conn, h *hub, srv *wsServer) *wsClient {
	if ws == nil {
		log.Panicln("ws cannot be nil")
	}

	if srv == nil {
		log.Panicln("server cannot be nil")
	}

	maxID++

	return &wsClient{
		id:   maxID,
		ws:   ws,
		h:    h,
		srv:  srv,
		subs: make(map[string]string),

		inMsgChan:  make(chan *wsMessage),
		outMsgChan: make(chan *wsMessage),
		doneChan:   make(chan bool),

		socketID: sha1Sum(fmt.Sprintf("%s-%s-%d", ws.RemoteAddr().String(),
			ws.LocalAddr().String(), maxID)),
	}
}

示例#19
文件: Config.go 项目: sinni800/sgemu

func CreateConfig() (f *os.File, e error) {
	f, e = os.Create(configPath)
	if e != nil {
		return nil, e
	}

	defer f.Close()

	Config = &ConfigData{
		LSConfig:  &LoginServerConfig{"127.0.0.1", "127.0.0.1", 3000},
		GSConfig:  &GameServerConfig{"127.0.0.1", "127.0.0.1", 13010},
		RPCConfig: &RPCConfig{"127.0.0.1", "127.0.0.1", 1234},
	}

	b, e := xml.MarshalIndent(Config, "", "\t")
	if e != nil {
		log.Panicln(e)
	}
	_, e = f.Write(b)
	if e != nil {
		log.Panicln(e)
	}

	return f, nil
}

示例#20
文件: filedialog.go 项目: xakep666/govkmedia

func SelectFolderDialog() string {
	engine := qml.NewEngine()
	component, err := engine.LoadFile("qrc:///qml/filedialog.qml")
	if err != nil {
		log.Panicln(err)
	}
	window := component.CreateWindow(nil)
	curuser, err := user.Current()
	if err != nil {
		log.Panicln(err) //system error
	}
	fd := window.Root().ObjectByName("filedialog")
	fd.Set("folder", curuser.HomeDir)
	window.Root().Call("setupForFolder")
	path := make(chan string)
	window.Root().On("gotpath", func() {
		if window.Root().Bool("cancelled") {
			path <- ""
		} else {
			path <- fd.String("fileUrl")
		}
	})
	window.Show()
	return strings.Replace(<-path, "file://", "", 1)
}

示例#21
文件: widgets.go 项目: jroimartin/gocui

func main() {
	g, err := gocui.NewGui(gocui.OutputNormal)
	if err != nil {
		log.Panicln(err)
	}
	defer g.Close()

	g.Highlight = true
	g.SelFgColor = gocui.ColorRed

	help := NewHelpWidget("help", 1, 1, helpText)
	status := NewStatusbarWidget("status", 1, 7, 50)
	butdown := NewButtonWidget("butdown", 52, 7, "DOWN", statusDown(status))
	butup := NewButtonWidget("butup", 58, 7, "UP", statusUp(status))
	g.SetManager(help, status, butdown, butup)

	if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
		log.Panicln(err)
	}
	if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, toggleButton); err != nil {
		log.Panicln(err)
	}

	if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
		log.Panicln(err)
	}
}

示例#22
文件: filesession.go 项目: JoeyFan/framework

func (s *SessionManager) Set(session map[string]interface{}, rw http.ResponseWriter, req *http.Request) {
	c, cerr := req.Cookie(s.CookieName)
	lsess := len(session)
	if cerr == nil {
		sessionSign := c.Value
		if lsess > 0 {
			if encodeSession, err := encodeGob(session); err == nil {
				writeFile(s.sessionDir+sessionSign+".golanger", encodeSession)
			} else {
				log.Panicln("filesession(encodeGob) error:", err)
			}
		} else {
			s.Clear(sessionSign)
		}
	} else {
		if lsess > 0 {
			if encodeSession, err := encodeGob(session); err == nil {
				sessionSign := s.new(rw)
				writeFile(s.sessionDir+sessionSign+".golanger", encodeSession)
			} else {
				log.Panicln("filesession(encodeGob) error:", err)
			}
		}
	}
}

示例#23
文件: config.go 项目: Dataman-Cloud/zookeeper-helper

func init() {
	jww.SetLogThreshold(jww.LevelTrace)
	jww.SetStdoutThreshold(jww.LevelInfo)

	log.Println("initing config ...")

	viper.SetConfigName("zookeeper-helper")
	viper.AddConfigPath("./")
	viper.AddConfigPath("$HOME/.omega/")
	viper.AddConfigPath("/etc/omega/")
	viper.SetConfigType("yaml")

	if err := viper.ReadInConfig(); err != nil {
		log.Panicln("can't read config file:", err)
	}

	initDefault()

	if err := viper.Unmarshal(&pairs); err != nil {
		log.Panicln("can't covert to config pairs: ", err)
	}

	if !pairs.Debugging {
		jww.SetLogThreshold(jww.LevelError)
		jww.SetStdoutThreshold(jww.LevelError)
	}

	log.Printf("initialized config pairs: %+v\n", pairs)
}

示例#24
文件: go-watch.go 项目: mkrapp/go-watch

func main() {
	var err error

	if _, err := os.Stat(projFile); os.IsNotExist(err) {
		projects = Projects{}
	} else {
		projects = read(projFile)
	}

	g := gocui.NewGui()
	if err := g.Init(); err != nil {
		log.Panicln(err)
	}
	defer g.Close()

	g.SetLayout(layout)
	if err := keybindings(g); err != nil {
		log.Panicln(err)
	}
	g.SelBgColor = gocui.ColorGreen
	g.SelFgColor = gocui.ColorBlack
	//g.ShowCursor = true

	err = g.MainLoop()
	if err != nil && err != gocui.Quit {
		log.Panicln(err)
	}
}

示例#25
文件: test_client3.go 项目: alxzh/two-queues

// Subscribes to all channels, keeping a count of the number of
// messages received. Publishes and resets the total every second.
func Subscriber() {
	client := NewClient()
	for _, channel := range channels {
		if err := client.Subscribe(channel); err != nil {
			log.Panicln(err)
		}
	}
	last := time.Now()
	messages := 0
	for {
		if _, err := client.Receive(); err != nil {
			log.Panicln(err)
		}
		messages += 1
		now := time.Now()
		if now.Sub(last).Seconds() > 1 {
			if !quiet {
				println(messages, "msg/sec")
			}
			if err := client.Publish("metrics", strconv.Itoa(messages)); err != nil {
				log.Panicln(err)
			}
			last = now
			messages = 0
		}
	}
}

示例#26
文件: main.go 项目: grafov/dbcom

func main() {
	var err error

	// TODO show base pane
	g := gocui.NewGui()
	if err = g.Init(); err != nil {
		log.Panicln(err)
	}
	defer g.Close()

	g.SetLayout(baseLayout)

	if err = initKeys(g); err != nil {
		log.Panicln(err)
	}

	// TODO init db on demand

	// for stub just init test db with hardcoded values
	if err = db.Add("test", "mysql", "root:[email protected]/test"); err != nil {
		log.Panicln(err)
	}

	if err = g.MainLoop(); err != nil && err != gocui.ErrQuit {
		log.Panicln(err)

	}
}

示例#27
文件: DataLoader.go 项目: sinni800/sgemu

func LoadRanks(Done chan bool) {
	defer func() {
		if x := recover(); x != nil {
			log.Printf("%v\n%s", x, C.PanicPath())
			Done <- false
		} else {
			Done <- true
		}
	}()

	f, e := os.Open(ranksPath)
	if e != nil {
		log.Panicln(e)
	}

	defer f.Close()

	type dummyXML struct {
		XMLName xml.Name    `xml:"Ranks"`
		Ranks   []*RankData `xml:"Rank"`
	}

	l := &dummyXML{}

	e = xml.NewDecoder(f).Decode(l)
	if e != nil {
		log.Panicln(e)
	}

	for _, rank := range l.Ranks {
		Ranks[rank.Level] = rank
	}
}

示例#28
文件: main.go 项目: lantiao/excel2json

func NewExcel2Json() *Excel2Json {
	path, err := os.Getwd() //当前路径
	if err != nil {
		log.Fatalln("获取路出错.")
	}
	f, err := os.Open(filepath.Join(path, "conf.json")) //JSON配置文件
	if err != nil {
		log.Panicln("读取配置文件失败.")
	}
	defer f.Close()
	fd, err := ioutil.ReadAll(f)
	jsonConf, err := simplejson.NewJson(fd)
	if err != nil {
		log.Panicln("解析配置文件出错.")
	}
	excel_dir, _ := jsonConf.Get("excel_dir").String()
	excel_dir, _ = filepath.Abs(excel_dir)
	json_dir, _ := jsonConf.Get("json_dir").String()
	json_dir, _ = filepath.Abs(json_dir)
	os.MkdirAll(json_dir, 0666) //创建json存放目录
	show_warning, _ := jsonConf.Get("show_warning").Bool()

	return &Excel2Json{
		curPath:     path,               //当前路径
		jsonDir:     json_dir,           //json存放目录
		excelDir:    excel_dir,          //excel源目录
		showWarning: show_warning,       //转换时是否显示警告
		jsonConf:    jsonConf,           //配置读取
		suc:         make([]baseMsg, 0), //转换成功记录
		fail:        make([]baseMsg, 0), //转换成功失败
		warn:        make([]baseMsg, 0), //配置可能有误的记录
	}
}

示例#29
文件: main.go 项目: cloudawan/zabbix_agent

func executeLongPolling(requestURL string, commandSliceTemplate []string) error {
	request, err := http.NewRequest("GET", requestURL, nil)
	if err != nil {
		log.Panicln(err)
		return err
	}
	client := http.Client{}
	response, err := client.Do(request)
	if err != nil {
		log.Panicln(err)
		return err
	}
	byteSlice := make([]byte, bufferSize)
	for {
		n, err := response.Body.Read(byteSlice)
		if err != nil {
			log.Panicln(err)
			return err
		}

		commandSlice := append(commandSliceTemplate, string(byteSlice[:n]))
		sendEvent(commandSlice)

		fmt.Println(string(byteSlice[:n]))
		time.Sleep(checkingInterval)
	}

	return nil
}

示例#30
文件: gui.go 项目: hojgr/cook

func (gui *GUI) Setup(callback func(g *GUI)) {

	var err error

	g := gocui.NewGui()
	g.ShowCursor = true

	if err = g.Init(); err != nil {
		log.Panicln(err)
	}

	defer g.Close()

	g.SetLayout(layout)

	gui.Gocui = g

	registerKeybindings(gui)

	go func() {
		waitForMainLoop := time.NewTimer(time.Millisecond * 10)
		<-waitForMainLoop.C
		callback(gui)
	}()

	err = gui.Gocui.MainLoop()

	if err != nil && err != gocui.Quit {
		log.Panicln(err)
	}
}

展开阅读全文