cleanerxiaoqiang 2019-06-30
type Video struct{
VideoID string `json:"video_id"`
//包含很多节目的属性,如节目类型,上下线状态等
}
type Show struct{
ShowID string `json:"show_id"`
//包含很多节目集的属性,如评分,演员等
}package es
import (
"context"
"log"
"encoding/json"
"github.com/olivere/elastic"
)
func(video *Video) ReadVideo(videoID string){
client,_ := elastic.NewClient(elastic.SetURL("http://127.0.0.1:19200"))
defer client.Stop()
if !isVideoExists(videoID){
return
}
esResponse,err := client.Get().Index("video").Type("video").Id(videoID).Do(context.Background())
if err != nil {
log.Println("Failed to read ES data of ID:! ",videoID)
return
}
json.Unmarshal(*esResponse.Source,&video)
}
func isVideoExists(videoID string)bool{
client,_ := elastic.NewClient(elastic.SetURL("http://127.0.0.1:19200"))
defer client.Stop()
exist,_ := client.Exists().Index("video").Type("video").Id(videoID).Do(context.Background())
if !exist{
log.Println("video ID may be incorrect! ",videoID)
return false
}
return true
}
func(show *Show) ReadShow(showID string){
client,_ := elastic.NewClient(elastic.SetURL("http://127.0.0.1:19200"))
defer client.Stop()
if !isShowExists(showID){
return
}
esResponse,err := client.Get().Index("show").Type("show").Id(showID).Do(context.Background())
if err != nil {
log.Println("Failed to read ES data of ID:! ",showID)
return
}
json.Unmarshal(*esResponse.Source,&show)
}
func isShowExists(showID string)bool{
client,_ := elastic.NewClient(elastic.SetURL("http://127.0.0.1:19200"))
defer client.Stop()
exist,_ := client.Exists().Index("show").Type("show").Id(showID).Do(context.Background())
if !exist{
log.Println("show ID may be incorrect! ",showID)
return false
}
return true
}func Read(media interface{}, mediaType, id string){
client,_ := elastic.NewClient(elastic.SetURL("http://127.0.0.1:19200"))
defer client.Stop()
if !isExists(id){
return
}
esResponse,err := client.Get().Index(mediaType).Type(mediaType).Id(id).Do(context.Background())
if err != nil {
log.Println("Failed to read ES data of ID:! ",id)
return
}
json.Unmarshal(*esResponse.Source,&media)
}
func isExists(mediaType, id string)bool{
client,_ := elastic.NewClient(elastic.SetURL("http://127.0.0.1:19200"))
defer client.Stop()
exist,_ := client.Exists().Index(mediaType).Type(mediaType).Id(id).Do(context.Background())
if !exist{
log.Println("ID may be incorrect! ",id)
return false
}
return true
}package es
import (
"context"
"log"
"encoding/json"
"github.com/olivere/elastic"
)
type Video struct{
VideoID string `json:"video_id"`
//包含很多节目的其他属性,如节目类型,上下线状态等,此处省略
}
type Show struct{
ShowID string `json:"show_id"`
//包含很多节目集的其他属性,如评分,演员等,此处省略
}
func(video *Video) read(videoID string){}
func(show *Show) read(showID string){}
type reader interface {
read()
}
type esPath struct{
ESIndex string
ESType string
ESID string
}
func Read(reader reader,esPath *esPath){
client ,_:= ESClient()
defer client.Stop()
if !isExists(esPath){
return
}
esResponse,err := client.
Get().Index(esPath.ESIndex).Type(esPath.ESType).Id(esPath.ESID).Do(context.Background())
if err != nil {
logger.LogPrintln("Failed to read ES data of ID:! ",esPath.ESID)
return
}
json.Unmarshal(*esResponse.Source,&reader)
}
func isExists(esPath *esPath)bool{
client,_ := ESClient()
defer client.Stop()
exist,_ := client.Exists().Index(esPath.ESIndex).Type(esPath.ESType).Id(esPath.ESID).Do(context.Background())
if !exist{
logger.LogPrintln("ShowID may be incorrect! ",esPath.ESID)
return false
}
return true
}doctype html> HTML5使用UTF-8编码演示:。<meta charset="UTF-8">2.HTML5中如何嵌入音频?</audio>3.HTML5中如何嵌入视频?</video&