Skip to content

Instantly share code, notes, and snippets.

@meoww-bot
Forked from wendal/gist:4537679
Created April 11, 2022 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoww-bot/770559b3671d0bce10d6405ca6185646 to your computer and use it in GitHub Desktop.
Save meoww-bot/770559b3671d0bce10d6405ca6185646 to your computer and use it in GitHub Desktop.
演示golang转编码 (gb2312 --> utf8)
package main
import (
iconv "github.com/djimenez/iconv-go"
"io/ioutil"
"log"
"net/http"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
resp, err := http.Get("http://data.earthquake.cn/datashare/globeEarthquake_csn.html")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
input, err := ioutil.ReadAll(resp.Body)
out := make([]byte, len(input))
out = out[:]
iconv.Convert(input, out, "gb2312", "utf-8")
ioutil.WriteFile("out.html", out, 0644)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment