-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
49 lines (40 loc) · 874 Bytes
/
setup.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package titan
import (
"context"
"crypto/tls"
"fmt"
"log"
"github.com/a-h/gemini"
"github.com/a-h/gemini/mux"
"github.com/mibzman/gmitohtml/pkg/gmitohtml"
)
type Booster struct {
Router *mux.Mux
LaunchConfig
}
type LaunchConfig struct {
HTTPServer bool
HTTPPort int
GeminiServer bool
GeminiPort int
}
func Startup() Booster {
return Booster{
mux.NewMux(),
LaunchConfig{true, 80, true, 1965},
}
}
func (server Booster) Launch(domain string, cert tls.Certificate) error {
if server.HTTPServer {
gmitohtml.StartDaemon(domain+":"+fmt.Sprint(server.HTTPPort), domain, false)
}
if server.GeminiServer {
gem := gemini.NewDomainHandler(domain, cert, server.Router)
err := gemini.ListenAndServe(context.Background(), ":"+fmt.Sprint(server.GeminiPort), gem)
if err != nil {
log.Fatal("error:", err)
return err
}
}
return nil
}