本文整理匯總了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
}
示例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
}
示例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,
}
}
示例4: connClose
func connClose(con *mpd.Client) {
if con != nil {
con.Close()
}
}