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 *.prof
/vendor /vendor
debug
#main #main

View File

@ -3,11 +3,7 @@ LABEL maintainer="MiaoWoo<admin@yumc.pw>"
ENV LANG en_US.UTF-8 ENV LANG en_US.UTF-8
RUN yum install -y fontconfig git nano RUN yum install -y fontconfig
RUN git clone https://github.com/powerline/fonts.git --depth=1 && \
cd fonts && \
./install.sh && \
fc-cache
WORKDIR /root 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) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
uid, _ := uuid.NewV4() uid, _ := uuid.NewV4()
uuid := "html2pic-" + uid.String() 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" tempFile := *tempDir + "/" + uuid + ".html"
if 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) 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 url = "file://" + tempFile
os.Chmod(tempFile, 0755)
defer os.Remove(tempFile) defer os.Remove(tempFile)
} }
if url == "" { if url == "" {