-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.go
52 lines (48 loc) · 1.13 KB
/
record.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bytes"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"io/ioutil"
"log"
"strconv"
)
type Record struct {
AnnouncementIssue int
RegNo string
TmName string
IntCls int
ApplicationCn string
LegalPersonName string
PhoneNumber string
RegLocation string
Link string
}
func (r *Record) ToString() (uline []byte, err error) {
line := ""
line += strconv.Itoa(r.AnnouncementIssue)+","+r.RegNo+","+r.TmName+","+strconv.Itoa(r.IntCls)+","+r.ApplicationCn+","+r.LegalPersonName+","+r.PhoneNumber+","+r.RegLocation+","+r.Link+"\n"
uline, err = r.Utf8ToGbk([]byte(line))
if err != nil{
log.Fatal(err)
return
}
return
}
func (r *Record) GbkToUtf8(str []byte) (rs []byte, err error) {
rd := transform.NewReader(bytes.NewReader(str), simplifiedchinese.GBK.NewDecoder())
rs, err = ioutil.ReadAll(rd)
if err != nil {
log.Fatal(err)
return
}
return
}
func (r *Record) Utf8ToGbk(str []byte) (rs []byte, err error) {
rd := transform.NewReader(bytes.NewReader(str), simplifiedchinese.GBK.NewEncoder())
rs, err = ioutil.ReadAll(rd)
if err != nil {
log.Fatal(err)
return
}
return
}