Skip to content

Commit

Permalink
增加在tls的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
JessonChan committed Apr 10, 2023
1 parent 3dc1943 commit 2085edc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions can.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type Opts struct {
CookieSessionKey string
// gorilla cookie store 加密使用的key
CookieSessionSecure string
// TLS 文件
CertFile, KeyFile string
}

var defaultTplSuffix = []string{".tpl", ".html"}
Expand Down Expand Up @@ -134,7 +136,7 @@ func (can *Can) Run(as ...interface{}) error {
Envs(&defaultAddr)
Envs(&defaultOpts)

if loggerInitialed == false && defaultOpts.CanlogPath != "" && defaultOpts.CanlogPath != "console" {
if !loggerInitialed && defaultOpts.CanlogPath != "" && defaultOpts.CanlogPath != "console" {
InitLogger(canlog.NewFileWriter(defaultOpts.CanlogPath))
} else {
_, _ = canlog.GetLogger().Writer().Write(cangoMark)
Expand Down Expand Up @@ -166,7 +168,11 @@ func (can *Can) Run(as ...interface{}) error {
}

canlog.CanInfo("cango start success @ " + addr.String())
return can.srv.ListenAndServe()
if opts.CertFile != "" && opts.KeyFile != "" {
return can.srv.ListenAndServeTLS(opts.CertFile, opts.KeyFile)
} else {
return can.srv.ListenAndServe()
}
}

type GinHandler struct {
Expand Down

0 comments on commit 2085edc

Please sign in to comment.