本文整理汇总了Golang中github.com/qiniu/iconv.Open函数的典型用法代码示例。如果您正苦于以下问题:Golang Open函数的具体用法?Golang Open怎么用?Golang Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getPage
func (mp *MovableProperty) getPage() string {
urlStr := fmt.Sprintf("http://www.tpkonsale.moj.gov.tw/sale/sale1QryM.asp?pageno=%d", mp.PageNo)
resp, err := http.DefaultClient.Get(urlStr)
if err != nil {
log.Printf("%s has error, %s", alu.Caller(), err.Error())
return ""
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("%s has error, %s", alu.Caller(), err.Error())
return ""
}
resp.Body.Close()
cd, err := iconv.Open("utf-8//ignore", "big5")
if err != nil {
log.Printf("%s has error, %s", alu.Caller(), err.Error())
return ""
}
utf8 := cd.ConvString(string(b))
return utf8
}
示例2: main
func main() {
response, err := http.Get("http://14.18.207.155:8000/dev/raw-attachment/wiki/策划/数值数据/装备定义表.csv")
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
//fmt.Printf("%s\n", string(contents));
cd, err := iconv.Open("utf-8", "gbk")
if err != nil {
fmt.Printf("iconv open failed!")
return
}
defer cd.Close()
//gbk := cd.ConvString(string(contents));
//fmt.Printf("%s\n", gbk);
fout, err := os.Create("./tmp.csv")
defer fout.Close()
if err != nil {
fmt.Println("创建临时文件失败: ", err)
return
}
fout.WriteString(cd.ConvString(string(contents)))
dump2sql()
}
}
示例3: MeiMingTang
//抓取美名堂数据(http://www.sheup.net/mingzi_boy_5.php?page=40&id=139)
func MeiMingTang() {
arr := make([]string, 5000)
// 初始化转码
cv, err := iconv.Open("utf-8", "gbk") // convert utf-8 to gbk
if err != nil {
log.Println("iconv.Open failed!")
return
}
defer cv.Close()
m := 0
for i := 1; i <= 40; i++ {
doc, err := goquery.NewDocument("http://www.sheup.net/mingzi_boy_5.php?page=" + strconv.Itoa(i) + "&id=139")
if err != nil {
log.Fatal(err)
}
doc.Find(".mingzi_s ul li").Each(func(j int, contentSelection *goquery.Selection) {
m++
title := contentSelection.Text()
arr[m] = cv.ConvString(title)
log.Println("第", m, "个名字:", arr[m])
})
}
}
示例4: init
func init() {
var err error
ic, err = iconv.Open("utf-8", "gbk")
if err != nil {
glog.Fatal("iconv.Open failed!")
}
}
示例5: main
func main() {
// request := gorequest.New()
// _, body, errs := request.Get("http://mm.howkuai.com/wp-content/uploads/2015a/11/20/01.jpg").End()
// if errs == nil {
// image := []byte(body)
// ioutil.WriteFile("1.jpg", image, 0644)
// }
doc, err := goquery.NewDocument("http://www.meizitu.com/")
if err != nil {
fmt.Println(err.Error())
}
doc.Find(".tags a").Each(func(_ int, s *goquery.Selection) {
url, _ := s.Attr("href")
title := s.Text()
cd, err := iconv.Open("utf-8", "gb2312")
if err != nil {
fmt.Println("iconv.Open failed!")
}
defer cd.Close()
title = cd.ConvString(title)
fmt.Println(title)
})
}
示例6: processFile
func processFile(filename, outputFilename string) {
lesson, err := parseLessonXml(filename)
if err != nil {
fmt.Printf("err: %v", err)
}
var path, content string
newXmlContent := &Lesson{}
cd, _ := iconv.Open("UTF-8", "big5")
defer cd.Close()
for i := 0; i < len(lesson.Files); i++ {
path = lesson.Files[i].Path
if !isUsefulFileType(path) {
continue
}
content = DecodeStr(lesson.Files[i].Content)
if strings.Contains(path, ".cond") {
content = cd.ConvString(content)
}
newXmlContent.Files = append(newXmlContent.Files, File{path, content})
}
err = outputNewXml("output/"+outputFilename, newXmlContent)
if err != nil {
fmt.Printf("err: %v", err)
}
defer wg.Done()
}
示例7: update
func update(db *(sql.DB), wiki_name string, table_name string) {
response, err := http.Get("http://14.18.207.155:8000/dev/raw-attachment/wiki/策划/数值数据/" + wiki_name + ".csv")
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
cd, err := iconv.Open("utf-8", "gbk")
if err != nil {
fmt.Printf("iconv open failed!")
return
}
defer cd.Close()
fout, err := os.Create("./tmp.csv")
defer fout.Close()
if err != nil {
fmt.Println("创建临时文件失败: ", err)
return
}
fout.WriteString(cd.ConvString(string(contents)))
load2db(db, table_name)
}
}
示例8: main
func main() {
urls = make(map[string]int)
itemReg = regexp.MustCompile(`http://item\.taobao\.com/item\.htm\?id=\d+`)
itemIdReg = regexp.MustCompile(`\d+`)
itemLevelReg = regexp.MustCompile(`level:"(\d+)",count:"(\d+)"`)
cd, _ = iconv.Open("gbk", "utf-8")
getShop("http://feiliao888.taobao.com/")
getShop("http://daisystyle.taobao.com/")
getShop("http://molixiang.taobao.com/")
getShop("http://shop103755843.taobao.com/")
getShop("http://tutu0.taobao.com/")
getShop("http://liv-fashion.taobao.com/")
getShop("http://shop35430112.taobao.com/")
getShop("http://rumere.taobao.com/")
getShop("http://iamfino.taobao.com/")
getShop("http://heyahua.taobao.com/")
getShop("http://pinyitang.taobao.com/")
getShop("http://lhzh.taobao.com/")
getShop("http://fanxiongmengxiang.taobao.com/")
getShop("http://mygod1.taobao.com/")
getShop("http://tywf.taobao.com/")
getShop("http://zhujiazhuang.taobao.com/")
getShop("http://quanjuner.taobao.com/")
getShop("http://wmbzp.taobao.com/")
getShop("http://fanfan0427.taobao.com/")
getShop("http://lecoor.taobao.com/")
getShop("http://coffeeandcigarettes.taobao.com/")
getShop("http://happy123.taobao.com/")
getShop("http://hzjrfs.taobao.com/")
getShop("http://jmjgroup.taobao.com/")
getShop("http://jmjgroup.taobao.com/")
getShop("http://jmjgroup.taobao.com/")
}
示例9: UploadDevice
func UploadDevice(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
w.Header().Add("Content-type", "text/html; charset=utf-8")
r.ParseForm()
file, handle, err := r.FormFile("file")
if err != nil {
w.Write([]byte("{\"Message\":\"" + err.Error() + "\",\"Status\":\"error\"}"))
return
}
cd, err := iconv.Open("UTF-8", "GBK")
if err != nil {
w.Write([]byte("{\"Message\":\"" + err.Error() + "\",\"Status\":\"error\"}"))
return
}
defer cd.Close()
dir := "/tmp/cloudboot-server/"
if !util.FileExist(dir) {
err := os.MkdirAll(dir, 0777)
if err != nil {
w.Write([]byte("{\"Message\":\"" + err.Error() + "\",\"Status\":\"error\"}"))
return
}
}
list := strings.Split(handle.Filename, ".")
fix := list[len(list)-1]
h := md5.New()
h.Write([]byte(fmt.Sprintf("%s", time.Now().UnixNano()) + handle.Filename))
cipherStr := h.Sum(nil)
md5 := fmt.Sprintf("%s", hex.EncodeToString(cipherStr))
filename := "osinstall-upload-" + md5 + "." + fix
result := make(map[string]interface{})
result["result"] = filename
if util.FileExist(dir + filename) {
os.Remove(dir + filename)
}
f, err := os.OpenFile(dir+filename, os.O_WRONLY|os.O_CREATE, 0666)
io.Copy(f, file)
if err != nil {
w.Write([]byte("{\"Message\":\"" + err.Error() + "\",\"Status\":\"error\"}"))
return
}
defer f.Close()
defer file.Close()
data := map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": result}
json, err := json.Marshal(data)
if err != nil {
w.Write([]byte("{\"Message\":\"" + err.Error() + "\",\"Status\":\"error\"}"))
return
}
w.Write([]byte(json))
return
}
示例10: Encoding_U82G
func Encoding_U82G(src string) string {
cd, err := iconv.Open("GBK", "UTF-8//IGNORE")
if err != nil {
fmt.Println("open iconv error")
return ""
}
defer cd.Close()
return cd.ConvString(src)
}
示例11: utf8ToGbk
func utf8ToGbk(s string) (string, error) {
cd, err := iconv.Open("gbk", "utf-8")
if err != nil {
return "", err
}
defer cd.Close()
gbk := cd.ConvString(s)
return gbk, nil
}
示例12: WriteGBK
// WriteGBK write a string to the printer with GBK encode
func (e *Escpos) WriteGBK(data string) (int, error) {
cd, err := iconv.Open("gbk", "utf-8")
if err != nil {
beelog.Critical("iconv.Open failed!")
return 0, err
}
defer cd.Close()
gbk := cd.ConvString(data)
return e.WriteRaw([]byte(gbk))
}
示例13: Encoding_U82U
func Encoding_U82U(src string) string {
cd, err := iconv.Open("UTF8", "UNICODE")
if err != nil {
fmt.Println("open iconv error")
return ""
}
defer cd.Close()
return cd.ConvString(src)
}
示例14: Encoding_G2U8
func Encoding_G2U8(src string) string {
cd, err := iconv.Open("UTF-8", "GBK")
if err != nil {
fmt.Println("open iconv error")
return ""
}
defer cd.Close()
return cd.ConvString(src)
}
示例15: new_utf8_reader
func new_utf8_reader(charset string, in io.Reader) (io.ReadCloser, error) {
if charset == "utf-8" || charset == "" {
return ioutil.NopCloser(in), nil
}
converter, err := iconv.Open("utf-8", charset)
if err != nil {
return nil, err
}
ireader := iconv.NewReader(converter, in, 0)
return &utf8_readcloser{converter, ireader}, nil
}