-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
72 lines (62 loc) · 1.32 KB
/
main.go
File metadata and controls
72 lines (62 loc) · 1.32 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"fmt"
"github.com/gin-gonic/gin"
"github.com/kbinani/screenshot"
"image/png"
"io"
"net/http"
"os"
)
var (
//Server gin flameworkのserver
Server *gin.Engine
)
func main(){
Server = gin.Default()
Server.GET("/github/read",ReadImage())
Server.GET("/github/a",A())
addr := GetServerPort()
Server.Run(addr)
}
func ReadImage()gin.HandlerFunc {
return func(c *gin.Context) {
user :=c.GetHeader("user")
var url string
url = "https://github-readme-stats.vercel.app/api?username="+user+"&count_private=true&show_icons=true"
fmt.Println(url)
response, err := http.Get(url)
if err != nil {
panic(err)
}
defer response.Body.Close()
file, err := os.Create("save.png")
if err != nil {
panic(err)
}
defer file.Close()
io.Copy(file, response.Body)
}
}
func A()gin.HandlerFunc {
return func(c *gin.Context) {
bounds := screenshot.GetDisplayBounds(0)
img, _ := screenshot.CaptureRect(bounds)
file, _ := os.Create("out.png")
defer file.Close()
png.Encode(file, img)
}
}
func GetServerPort() string{
var addr string
port := os.Getenv("PORT")
if (port == "") {
port = "8080"
}
// 接続情報は以下のように指定する.
// user:password@tcp(host:port)/database
flag.StringVar(&addr, "addr", ":"+port, "tcp host:port to connect")
flag.Parse()
return addr
}