本文整理汇总了Golang中log.Panicln函数的典型用法代码示例。如果您正苦于以下问题:Golang Panicln函数的具体用法?Golang Panicln怎么用?Golang Panicln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Panicln函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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: LoadBinds
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: LoadItems
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: main
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
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: NewClient
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: guiUpdater
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: TestRoute
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: main
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: request
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: main
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
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: getUserInfo
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
//命令行操作
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
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)
}
}
}
}