Skip to content

Commit

Permalink
feature(): dockered , log added
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglikun committed Sep 4, 2018
1 parent 00277fc commit 178719a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
COPY ghca /
EXPOSE 8080
ENTRYPOINT ["/ghca"]
CMD ["--server"]
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
chmod +x ./ghca
docker build -t fatalc/ghca .
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"github.com/fatalc/ghca/encrypt"
"github.com/fatalc/ghca/server"
"log"
Expand All @@ -13,6 +14,7 @@ var (
username = flag.String("username", "", "参与算号的账户")
password = flag.String("password", "", "参与算号的账户密码")
isServer = flag.Bool("server", false, "是否以web服务器方式启动")
port = flag.Int("port", 8080, "web服务器监听端口")
)

func init() {
Expand All @@ -21,7 +23,8 @@ func init() {
func main() {
if *isServer {
http.Handle("/", &server.GhcaHandler{})
log.Fatal(http.ListenAndServe(":8080", nil))
log.Printf("ghca server 在端口%d,上运行...", *port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
}
if *isServer == false && *username == "" || *password == "" {
println("当不以服务器形式启动时, {username} 与 {password} 必需被设置")
Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"github.com/fatalc/ghca/encrypt"
"log"
"net/http"
)

Expand All @@ -13,6 +14,7 @@ type GhcaHandler struct {
}

func (*GhcaHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
log.Print(request.URL)
writer.Header().Set("Content-Type", "application/json")
username := request.URL.Query().Get("username")
password := request.URL.Query().Get("password")
Expand Down

0 comments on commit 178719a

Please sign in to comment.