本文整理汇总了Golang中github.com/toukii/goutils.CheckErr函数的典型用法代码示例。如果您正苦于以下问题:Golang CheckErr函数的具体用法?Golang CheckErr怎么用?Golang CheckErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CheckErr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Unzip
func Unzip(zip_filename, target string) (err error) {
zr, err := zip.OpenReader(zip_filename)
defer zr.Close()
if goutils.CheckErr(err) {
return
}
var target_filename string
for _, it := range zr.File {
fmt.Println(it.Name)
target_filename = filepath.Join(target, it.Name)
if it.FileInfo().IsDir() {
os.MkdirAll(target_filename, 0666)
continue
}
of, err := os.OpenFile(target_filename, os.O_CREATE|os.O_WRONLY, 0666)
defer of.Close()
if goutils.CheckErr(err) {
continue
}
rit, err := it.Open()
defer rit.Close()
_, err = io.Copy(of, rit)
if goutils.CheckErr(err) {
continue
}
}
return nil
}
示例2: Untar
func Untar(tar_filename, target string) (err error) {
file, err := os.OpenFile(tar_filename, os.O_RDONLY, 0444)
defer file.Close()
if goutils.CheckErr(err) {
return
}
tr := tar.NewReader(file)
var target_filename string
for {
hr, err := tr.Next()
if err == io.EOF {
break
}
fmt.Println(hr.FileInfo().Name())
target_filename = filepath.Join(target, hr.Name)
if hr.FileInfo().IsDir() {
os.MkdirAll(target_filename, 0666)
continue
}
of, err := os.OpenFile(target_filename, os.O_CREATE|os.O_WRONLY, 0666)
defer of.Close()
if goutils.CheckErr(err) {
continue
}
_, err = io.Copy(of, tr)
if goutils.CheckErr(err) {
continue
}
}
return nil
}
示例3: markdownCBQiniu
func markdownCBQiniu(rw http.ResponseWriter, req *http.Request) {
req.ParseForm()
rawContent := req.Form.Get("rawContent")
// fmt.Println(rawContent)
fmt.Print(",")
out := make([]byte, 0, 100)
in := goutils.ToByte(rawContent)
RPC_Client = rpcsv.RPCClient(rpc_tcp_server)
err := rpcsv.Markdown(RPC_Client, &in, &out)
if goutils.CheckErr(err) {
rw.Write(goutils.ToByte(err.Error()))
return
}
qiniuWriter.Reset()
qiniuWriter.Write(goutils.ToByte("CallbackFunc(`"))
data := make(map[string]interface{})
data["MDContent"] = template.HTML(goutils.ToString(out))
err = rpcsv.Theme.Execute(qiniuWriter, data)
if goutils.CheckErr(err) {
rw.Write(goutils.ToByte(err.Error()))
}
qiniuWriter.Write(goutils.ToByte("`)"))
rw.Write(qiniuWriter.Bytes())
writeCrossDomainHeaders(rw, req)
}
示例4: GenerateOjModle
func GenerateOjModle(path_ string, m *Model) error {
_, err := os.Stat(path_)
if !goutils.CheckErr(err) {
os.RemoveAll(path_)
}
err = os.Mkdir(path_, 0777)
if goutils.CheckErr(err) {
// return err
}
fname := m.FuncName + ".go"
tname := m.FuncName + "_test.go"
func_file, err := os.OpenFile(filepath.Join(path_, fname), os.O_CREATE|os.O_WRONLY, 0644)
defer func_file.Close()
if goutils.CheckErr(err) {
return err
}
if goutils.CheckErr(generateOjFunc(m.Content, func_file)) {
return fmt.Errorf("generateOjFunc error")
}
test_file, err := os.OpenFile(filepath.Join(path_, tname), os.O_CREATE|os.O_WRONLY, 0644)
defer test_file.Close()
if goutils.CheckErr(err) {
return err
}
args := make(map[string]interface{})
args["FUNC"] = m.FuncName
args["ArgsType"] = m.ArgsType
args["RetsType"] = m.RetsType
args["TestCases"] = m.TestCases
return renderOjModle(args, test_file)
}
示例5: renderFile
func renderFile(filename string, redo bool) bool {
_, err := os.Lstat(filename + ".html")
if !redo && nil == err {
return false
}
if nil == err {
err = os.Remove(filename + ".html")
goutils.CheckErr(err)
}
input := readFile(filename)
if nil == input {
return false
}
// unsafe := blackfriday.MarkdownCommon(input)
// html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
html := md.Markdown(input)
data := make(map[string]interface{})
data["MDContent"] = goutils.ToString(html)
data["Title"] = getName(filename)
of, err := os.OpenFile( /*targetDir+string(os.PathSeparator)+*/ filename+".html", os.O_CREATE|os.O_RDWR, 0666)
defer of.Close()
if goutils.CheckErr(err) {
return false
}
err = theme.Execute(of, data)
if goutils.CheckErr(err) {
return false
}
return true
}
示例6: ExtractFunc
func ExtractFunc(path string, info os.FileInfo, err error) error {
if strings.EqualFold(".git", info.Name()) {
return filepath.SkipDir
}
if strings.HasPrefix(path, base) {
return filepath.SkipDir
}
if info.IsDir() {
err = os.Mkdir(home+Spor+path, 0644)
if goutils.CheckErr(err) {
return nil
}
}
if strings.EqualFold(ext, filepath.Ext(path)) {
orf, err := os.OpenFile(path, os.O_RDONLY, 0644)
defer orf.Close()
if goutils.CheckErr(err) {
return nil
}
owf, err := os.OpenFile(base+string(os.PathSeparator)+path, os.O_CREATE|os.O_WRONLY, 0622)
defer owf.Close()
if goutils.CheckErr(err) {
return nil
}
n, err := io.Copy(owf, orf)
fmt.Printf("%s: %d bytes.\n", path, n)
}
return nil
}
示例7: markdown
func markdown(rw http.ResponseWriter, req *http.Request) {
req.ParseForm()
rawContent := req.Form.Get("rawContent")
// fmt.Println(req.RemoteAddr, req.Referer())
fmt.Print(".")
// fmt.Println(rawContent)
out := make([]byte, 0, 100)
in := goutils.ToByte(rawContent)
times := 0
connect()
retry:
times++
err := rpcsv.Markdown(RPC_Client, &in, &out)
if goutils.CheckErr(err) {
connect()
if times < 6 {
goto retry
}
rw.Write(goutils.ToByte(err.Error()))
return
}
data := make(map[string]interface{})
data["MDContent"] = template.HTML(goutils.ToString(out))
err = rpcsv.Theme.Execute(rw, data)
if goutils.CheckErr(err) {
rw.Write(goutils.ToByte(err.Error()))
}
// if len(out) <= 0 {
// rw.Write(goutils.ToByte("{response:nil}"))
// return
// }
// writeCrossDomainHeaders(rw, req)
// rw.Write(out)
}
示例8: modifiedMD
// in: Linux/index.md
// out: ./MDFs
func modifiedMD(file_in, dir_out string) {
finfo, err := os.Stat(file_in)
if goutils.CheckErr(err) {
return
}
filename := finfo.Name()
dir := filepath.Dir(file_in)
fs := strings.Split(filename, ".")
in := goutils.ReadFile(file_in)
out := make([]byte, 1)
err = rpcsv.Markdown(rpc_client, &in, &out)
if goutils.CheckErr(err) {
return
}
// fmt.Println(goutils.ToString(out))
target := fmt.Sprintf("%s.html", filepath.Join(dir_out, dir, fs[0]))
goutils.Mkdir(fmt.Sprintf("%s", filepath.Join(dir_out, dir)))
outfile, _ := os.OpenFile(fmt.Sprintf("%s.html", filepath.Join(dir_out, dir, fs[0])), os.O_CREATE|os.O_WRONLY, 0666)
defer outfile.Close()
dt := make(map[string]interface{})
dt["MDContent"] = template.HTML(goutils.ToString(out))
tpl.Execute(outfile, dt)
fmt.Println(file_in, " ==> ", target)
}
示例9: ToM
func ToM() *Model {
b, err := ioutil.ReadFile("model.json")
goutils.CheckErr(err)
var ret Model
err = json.Unmarshal(b, &ret)
goutils.CheckErr(err)
return &ret
}
示例10: ToMs
func ToMs() []Model {
b, err := ioutil.ReadFile("models.json")
goutils.CheckErr(err)
var ret []Model
err = json.Unmarshal(b, &ret)
goutils.CheckErr(err)
return ret
}
示例11: MJ
func MJ() {
f, err := os.OpenFile("model.json", os.O_CREATE|os.O_WRONLY, 0644)
goutils.CheckErr(err)
m := NewModel()
b, err := json.MarshalIndent(m, "", "\t")
goutils.CheckErr(err)
f.Write(b)
}
示例12: TiniuMs
// http://7xku3c.com1.z0.glb.clouddn.com/models.json
func TiniuMs(_url string) []Model {
resp, _ := http.Get(_url)
b, err := ioutil.ReadAll(resp.Body)
goutils.CheckErr(err)
var ret []Model
err = json.Unmarshal(b, &ret)
goutils.CheckErr(err)
return ret
}
示例13: readFile
func readFile(filename string) []byte {
file, err := os.OpenFile(filename, os.O_RDONLY, 0644)
if goutils.CheckErr(err) {
return nil
}
defer file.Close()
b, err := ioutil.ReadAll(file)
if goutils.CheckErr(err) {
return nil
}
return b
}
示例14: renderOjModle
func renderOjModle(args map[string]interface{}, w io.Writer) error {
b, err := ioutil.ReadFile("oj.tpl")
if goutils.CheckErr(err) {
return err
}
s := goutils.ToString(b)
tpl, err := template.New("oj.tpl").Parse(s)
if goutils.CheckErr(err) {
return err
}
return tpl.Execute(w, args)
}
示例15: RPCClient
func RPCClient(tcp_addr string) *rpc.Client {
addr, err := net.ResolveTCPAddr("tcp", tcp_addr)
if goutils.CheckErr(err) {
return nil
}
conn, err := net.DialTCP("tcp", nil, addr)
if goutils.CheckErr(err) {
return nil
}
rc := rpc.NewClient(conn)
return rc
}