-
Notifications
You must be signed in to change notification settings - Fork 3
/
andrew.go
30 lines (26 loc) · 1.28 KB
/
andrew.go
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
package andrew
import (
"io/fs"
)
// ListenAndServe creates a server in the contentRoot, listening at the address, with links on autogenerated
// pages to the baseUrl.
// contentRoot - an fs.FS at some location, whether that's a virtual fs.FS such as an fs.Testfs or an
//
// fs.FS at a location on your file system such as os.DirFS.
//
// contentRoot - an initialised fs.FS. Some implementation details sometimes differ amongst different fs.FS;
// Andrew internally uses an os.DirFS and tests with an fstest.MapFS, so those two have some code examples herein.
// address - an ip:port combination. The AndrewServer will bind an http server here.
// baseUrl - the hostname that you are hosting from.
// certInfo - certificate info type. If the members are empty, Andrew serves http.
func ListenAndServe(contentRoot fs.FS, address string, hostname string, certInfo *CertInfo, rssInfo *RssInfo) error {
andrewServer := NewServer(contentRoot, address, hostname, *rssInfo)
if certInfo != nil && certInfo.CertPath != "" && certInfo.PrivateKeyPath != "" {
// Use HTTPS with the provided certificate and key
err := andrewServer.ListenAndServeTLS(certInfo.CertPath, certInfo.PrivateKeyPath)
return err
}
// Fallback to HTTP if no certificate is provided
err := andrewServer.ListenAndServe()
return err
}