Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 90070e5

Browse files
you're doing great
1 parent 46d4aa3 commit 90070e5

File tree

20 files changed

+316
-2
lines changed

20 files changed

+316
-2
lines changed

‎000_temp/77-web-server/main.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
)
77

88
var tpl *template.Template
9-
109
func init() {
1110
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
1211
}

‎000_temp/78/assets/toby.jpg‎

5.04 KB
Loading[フレーム]

‎000_temp/78/main.go‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"fmt"
6+
"html/template"
7+
"os"
8+
"io"
9+
)
10+
11+
var tpl *template.Template
12+
13+
func init() {
14+
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
15+
}
16+
17+
18+
func main() {
19+
http.HandleFunc("/", foo)
20+
http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets"))))
21+
http.ListenAndServe(":8080", nil)
22+
}
23+
24+
func foo(w http.ResponseWriter, r *http.Request) {
25+
fmt.Println("Method", r.Method)
26+
27+
fn := ""
28+
29+
if r.Method == http.MethodPost {
30+
// open
31+
f, h, err := r.FormFile("q")
32+
if err != nil {
33+
http.Error(w, err.Error(), http.StatusInternalServerError)
34+
return
35+
}
36+
defer f.Close()
37+
38+
fn = h.Filename
39+
40+
df, err := os.Create("./assets/"+fn)
41+
if err != nil {
42+
http.Error(w, err.Error(), http.StatusInternalServerError)
43+
return
44+
}
45+
defer df.Close()
46+
47+
_, err = io.Copy(df, f)
48+
if err != nil {
49+
http.Error(w, err.Error(), http.StatusInternalServerError)
50+
return
51+
}
52+
}
53+
54+
// w.Header().Set("Content-Type", "text/html; charset=utf-8")
55+
56+
tpl.ExecuteTemplate(w, "index.gohtml", fn)
57+
}

‎000_temp/78/templates/index.gohtml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Document</title>
9+
</head>
10+
<body>
11+
12+
<form method="POST" enctype="multipart/form-data">
13+
<input type="file" name="q">
14+
<input type="submit">
15+
</form>
16+
<br>
17+
18+
{{if .}}
19+
file name: {{.}}
20+
<img src="/resources/{{.}}">
21+
{{end}}
22+
23+
</body>
24+
</html>

‎000_temp/79/main.go‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"html/template"
6+
"net/http"
7+
)
8+
9+
var tpl *template.Template
10+
11+
func init() {
12+
tpl = template.Must(template.ParseGlob("templates/*"))
13+
}
14+
15+
func main() {
16+
http.HandleFunc("/", foo)
17+
http.HandleFunc("/bar", bar)
18+
http.HandleFunc("/barred", barred)
19+
http.Handle("/favicon.ico", http.NotFoundHandler())
20+
http.ListenAndServe(":8080", nil)
21+
}
22+
23+
func foo(w http.ResponseWriter, req *http.Request) {
24+
25+
var s string
26+
27+
if req.Method == http.MethodPost {
28+
s = req.FormValue("fname")
29+
}
30+
31+
fmt.Print("Your request method at foo: ", req.Method, "\n")
32+
fmt.Print("Your FORM VALUE at foo: ", s, "\n\n")
33+
}
34+
35+
func bar(w http.ResponseWriter, req *http.Request) {
36+
fmt.Println("Your request method at bar:", req.Method)
37+
// process form submission here
38+
http.Redirect(w, req, "/", http.StatusSeeOther)
39+
}
40+
41+
func barred(w http.ResponseWriter, req *http.Request) {
42+
fmt.Println("Your request method at barred:", req.Method)
43+
tpl.ExecuteTemplate(w, "index.gohtml", nil)
44+
}

‎000_temp/79/templates/index.gohtml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
9+
<form method="POST" action="/bar">
10+
<input type="text" name="fname">
11+
<input type="submit">
12+
</form>
13+
14+
</body>
15+
</html>

‎000_temp/80-renamer/80-renamer.txt‎

2.1 MB
Binary file not shown.

‎000_temp/80-renamer/main.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
"strconv"
8+
)
9+
10+
func main() {
11+
12+
dir := "results/"
13+
files, _ := ioutil.ReadDir(dir)
14+
15+
for i, f := range files {
16+
fmt.Println(f.Name())
17+
oldfile := (dir + f.Name())
18+
newfile := (dir + strconv.Itoa(i) + ".txt")
19+
fmt.Println(oldfile, "named it to", newfile, "\n")
20+
21+
err := os.Rename(oldfile, newfile)
22+
if err != nil {
23+
fmt.Println(err)
24+
return
25+
}
26+
}
27+
}

‎000_temp/80-renamer/results/0.txt‎

Whitespace-only changes.

‎000_temp/80-renamer/results/1.txt‎

Whitespace-only changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /