/
app_listenAndServeAll.go
42 lines (37 loc) · 1.3 KB
/
app_listenAndServeAll.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
// Copyright 2017 Kirill Danshin and Gramework contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
package gramework
// ListenAndServeAll serves HTTP and HTTPS automatically.
// HTTPS is served on :443.
// If it can't serve http or https, it logs an error and
// exit the server with app.Logger.Fatalf().
func (app *App) ListenAndServeAll(httpAddr ...string) {
go func() {
err := app.ListenAndServeAutoTLS(":443")
app.Logger.Fatalf("can't serve tls: %s", err)
}()
if err := app.ListenAndServe(httpAddr...); err != nil {
app.Logger.Fatalf("can't serve http: %s", err)
}
}
// ListenAndServeAllDev serves HTTP and HTTPS automatically
// with localhost HTTPS support via self-signed certs.
// HTTPS is served on :443.
// If it can't serve http or https, it logs an error and
// exit the server with app.Logger.Fatalf().
func (app *App) ListenAndServeAllDev(httpAddr ...string) {
go func() {
if err := app.ListenAndServeAutoTLSDev(":443"); err != nil {
app.Logger.Fatalf("can't serve tls: %s", err)
}
}()
if err := app.ListenAndServe(httpAddr...); err != nil {
app.Logger.Fatalf("can't serve http: %s", err)
}
}