-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Embed file using golang embed filesystem #30
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package main | |
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
@@ -14,21 +15,29 @@ import ( | |
"github.com/gusaul/grpcox/handler" | ||
) | ||
|
||
var ( | ||
logfile string | ||
port int | ||
) | ||
|
||
func main() { | ||
flag.StringVar(&logfile, "log", "", "Specify log file") | ||
flag.IntVar(&port, "port", 6969, "Specify port server") | ||
flag.Parse() | ||
|
||
// logging conf | ||
f, err := os.OpenFile("log/grpcox.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) | ||
if err != nil { | ||
log.Fatalf("error opening file: %v", err) | ||
if logfile != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont need to check if have default value |
||
f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) | ||
if err != nil { | ||
log.Fatalf("error opening file: %v", err) | ||
} | ||
defer f.Close() | ||
log.SetOutput(f) | ||
log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
} | ||
defer f.Close() | ||
log.SetOutput(f) | ||
log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
|
||
// start app | ||
addr := "0.0.0.0:6969" | ||
if value, ok := os.LookupEnv("BIND_ADDR"); ok { | ||
addr = value | ||
} | ||
addr := fmt.Sprintf(":%d", port) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is breaking changes, we use env variable as config now, its should not completely replace, just make it replace if only being set by flag args |
||
muxRouter := mux.NewRouter() | ||
handler.Init(muxRouter) | ||
var wait time.Duration = time.Second * 15 | ||
|
@@ -59,7 +68,7 @@ func main() { | |
ctx, cancel := context.WithTimeout(context.Background(), wait) | ||
defer cancel() | ||
|
||
err = removeProtos() | ||
err := removeProtos() | ||
if err != nil { | ||
log.Printf("error while removing protos: %s", err.Error()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package index | ||
|
||
import "embed" | ||
|
||
//go:embed css/* font/* img/* js/* index.html | ||
var FS embed.FS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should have default value to
log/grpcox.log