1
0

fix: fix permission error

This commit is contained in:
502647092 2018-09-12 17:14:26 +08:00
parent c9c7834291
commit 4c1ad32681
5 changed files with 12 additions and 6 deletions

1
.gitignore vendored
View File

@ -25,4 +25,5 @@ _testmain.go
*.prof
/vendor
debug
#main

View File

@ -3,11 +3,7 @@ LABEL maintainer="MiaoWoo<admin@yumc.pw>"
ENV LANG en_US.UTF-8
RUN yum install -y fontconfig git nano
RUN git clone https://github.com/powerline/fonts.git --depth=1 && \
cd fonts && \
./install.sh && \
fc-cache
RUN yum install -y fontconfig
WORKDIR /root

BIN
main

Binary file not shown.

11
main.go
View File

@ -18,11 +18,20 @@ func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
uid, _ := uuid.NewV4()
uuid := "html2pic-" + uid.String()
url, html := r.PostFormValue("url"), r.PostFormValue("html")
var (
url string
html string
)
if r.Method == "GET" {
url, html = r.FormValue("url"), r.FormValue("html")
} else {
url, html = r.PostFormValue("url"), r.PostFormValue("html")
}
tempFile := *tempDir + "/" + uuid + ".html"
if html != "" {
ioutil.WriteFile(tempFile, []byte("<!DOCTYPE html><html lang=\"zh\"><head><meta charset=\"UTF-8\"></head><body style=\"margin: 0;padding: 0;\">"+html+"</body></html>"), os.ModeAppend)
url = "file://" + tempFile
os.Chmod(tempFile, 0755)
defer os.Remove(tempFile)
}
if url == "" {