當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.Close方法代碼示例

本文整理匯總了Golang中github.com/fhs/gompd/mpd.Client.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Close方法的具體用法?Golang Client.Close怎麽用?Golang Client.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/fhs/gompd/mpd.Client的用法示例。


在下文中一共展示了Client.Close方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: update

//Updates the library
func (l *library) update() error {
	var conn *mpd.Client

	fmt.Println("Connecting to MPD")
	conn, err := mpd.Dial("tcp", "127.0.0.1:6600")
	if err != nil {
		fmt.Println("Error: could not connect to MPD for lib update")
		return errors.New("Could not connect to MPD!")
	}
	defer conn.Close()

	_, err = conn.Update("")
	if err != nil {
		fmt.Println("Error: could not update library!")
		return err
	}

	//Let the update happen
	time.Sleep(2 * time.Second)
	songs, err := conn.ListAllInfo("/")
	if err != nil {
		fmt.Println("Error: could not retrieve new library!")
		return err
	}

	l.library = songs
	return nil
}
開發者ID:Luminarys,項目名稱:patchy,代碼行數:29,代碼來源:library.go

示例2: Render

func (m MPDInstance) Render() (item modules.Item) {
	mpdItem := MPDItem{Name: m.name, Markup: "pango"}
	mpdFormatData := MPDFormatData{}
	var client *go_mpd.Client

	if c, err := go_mpd.Dial("tcp", m.host_name+":"+strconv.Itoa(m.port)); err != nil {
		log.Error(err.Error())
		return nil
	} else {
		client = c
	}

	defer func(client *go_mpd.Client) {
		if err := client.Close(); err != nil {
			log.Error("Failed to disconnect: " + err.Error())
		}
	}(client)

	if attrs, err := client.Status(); err == nil {
		if state, ok := attrs["state"]; ok {
			mpdFormatData.State = state
		} else {
			log.Error("Failed to read state.")
			return nil
		}
	} else {
		log.Error("Failed to obtain status: " + err.Error())
		return nil
	}

	if attrs, err := client.CurrentSong(); err != nil {
		log.Error("Failed to obtain current song: " + err.Error())
		return nil
	} else {
		obj := reflect.ValueOf(&mpdFormatData).Elem()
		for key, val := range attrs {
			if f := obj.FieldByName(key); f.IsValid() {
				val = strings.TrimSpace(val)
				f.Set(reflect.ValueOf(val))
			}
		}
	}

	buffer := bytes.Buffer{}

	if err := m.template.Execute(&buffer, mpdFormatData); err != nil {
		log.Error("Failed to render mpd template: " + err.Error())
		return nil
	} else {
		mpdItem.Text = buffer.String()
	}

	item = mpdItem
	return
}
開發者ID:andir,項目名稱:go3status,代碼行數:55,代碼來源:mpd.go

示例3: newLibrary

//Create a new queue
func newLibrary() *library {
	var conn *mpd.Client

	fmt.Println("Connecting to MPD")
	conn, err := mpd.Dial("tcp", "127.0.0.1:6600")
	if err != nil {
		fmt.Println("Error: could not connect to MPD, exiting")
		os.Exit(1)
	}
	defer conn.Close()

	songs, err := conn.ListAllInfo("/")
	if err != nil {
		fmt.Println("Error: could not connect to MPD, exiting")
		os.Exit(1)
	}
	shuffle(songs)

	return &library{
		library: songs,
	}
}
開發者ID:Luminarys,項目名稱:patchy,代碼行數:23,代碼來源:library.go

示例4: connClose

func connClose(con *mpd.Client) {
	if con != nil {
		con.Close()
	}
}
開發者ID:KarolBedkowski,項目名稱:rpilcd,代碼行數:5,代碼來源:mpd.go


注:本文中的github.com/fhs/gompd/mpd.Client.Close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。