-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type Server struct { | ||
http.Server | ||
} | ||
|
||
type Config struct { | ||
// Hostname to use for download links | ||
Hostname string `toml:"hostname"` | ||
// Port is a server port to listen to | ||
Port int `toml:"port"` | ||
// Bind a specific IP addresses for server | ||
// "*": bind all IP addresses which is default option | ||
// localhost or 127.0.0.1 bind a single IPv4 address | ||
BindAddress string `toml:"bind_address"` | ||
// Specify path for reverse proxy and only [A-Za-z0-9] | ||
Path string `toml:"path"` | ||
// DataDir is a path to a directory to keep XML feeds and downloaded episodes, | ||
// that will be available to user via web server for download. | ||
DataDir string `toml:"data_dir"` | ||
} | ||
|
||
func New(cfg Config, storage http.FileSystem) *Server { | ||
port := cfg.Port | ||
if port == 0 { | ||
port = 8080 | ||
} | ||
|
||
bindAddress := cfg.BindAddress | ||
if bindAddress == "*" { | ||
bindAddress = "" | ||
} | ||
|
||
srv := Server{} | ||
|
||
srv.Addr = fmt.Sprintf("%s:%d", bindAddress, port) | ||
log.Debugf("using address: %s:%s", bindAddress, srv.Addr) | ||
|
||
fileServer := http.FileServer(storage) | ||
|
||
log.Debugf("handle path: /%s", cfg.Path) | ||
http.Handle(fmt.Sprintf("/%s", cfg.Path), fileServer) | ||
|
||
return &srv | ||
} |