-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: add comments to top of public functions and variables
- Loading branch information
1 parent
33b450d
commit 54b1f0a
Showing
11 changed files
with
133 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,91 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
"time" | ||
"context" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/maaslalani/slides/internal/model" | ||
"github.com/maaslalani/slides/internal/navigation" | ||
"github.com/maaslalani/slides/internal/server" | ||
"github.com/muesli/coral" | ||
"github.com/maaslalani/slides/internal/model" | ||
"github.com/maaslalani/slides/internal/navigation" | ||
"github.com/maaslalani/slides/internal/server" | ||
"github.com/muesli/coral" | ||
) | ||
|
||
var ( | ||
host string | ||
port int | ||
keyPath string | ||
err error | ||
fileName string | ||
host string | ||
port int | ||
keyPath string | ||
err error | ||
fileName string | ||
) | ||
|
||
ServeCmd = &coral.Command{ | ||
Use: "serve <file.md>", | ||
Aliases: []string{"server"}, | ||
Short: "Start an SSH server to run slides", | ||
Args: coral.ArbitraryArgs, | ||
RunE: func(cmd *coral.Command, args []string) error { | ||
k := os.Getenv("SLIDES_SERVER_KEY_PATH") | ||
if k != "" { | ||
keyPath = k | ||
} | ||
h := os.Getenv("SLIDES_SERVER_HOST") | ||
if h != "" { | ||
host = h | ||
} | ||
p := os.Getenv("SLIDES_SERVER_PORT") | ||
if p != "" { | ||
port, _ = strconv.Atoi(p) | ||
} | ||
// ServeCmd is the command for serving the presentation. It starts the slides | ||
// server allowing for connections. | ||
var ServeCmd = &coral.Command{ | ||
Use: "serve <file.md>", | ||
Aliases: []string{"server"}, | ||
Short: "Start an SSH server to run slides", | ||
Args: coral.ArbitraryArgs, | ||
RunE: func(cmd *coral.Command, args []string) error { | ||
k := os.Getenv("SLIDES_SERVER_KEY_PATH") | ||
if k != "" { | ||
keyPath = k | ||
} | ||
h := os.Getenv("SLIDES_SERVER_HOST") | ||
if h != "" { | ||
host = h | ||
} | ||
p := os.Getenv("SLIDES_SERVER_PORT") | ||
if p != "" { | ||
port, _ = strconv.Atoi(p) | ||
} | ||
|
||
if len(args) > 0 { | ||
fileName = args[0] | ||
} | ||
if len(args) > 0 { | ||
fileName = args[0] | ||
} | ||
|
||
presentation := model.Model{ | ||
Page: 0, | ||
Date: time.Now().Format("2006-01-02"), | ||
FileName: fileName, | ||
Search: navigation.NewSearch(), | ||
} | ||
err = presentation.Load() | ||
if err != nil { | ||
return err | ||
} | ||
presentation := model.Model{ | ||
Page: 0, | ||
Date: time.Now().Format("2006-01-02"), | ||
FileName: fileName, | ||
Search: navigation.NewSearch(), | ||
} | ||
err = presentation.Load() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s, err := server.NewServer(keyPath, host, port, presentation) | ||
if err != nil { | ||
return err | ||
} | ||
s, err := server.NewServer(keyPath, host, port, presentation) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
done := make(chan os.Signal, 1) | ||
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
log.Printf("Starting Slides server on %s:%d", host, port) | ||
go func() { | ||
if err = s.Start(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
}() | ||
done := make(chan os.Signal, 1) | ||
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
log.Printf("Starting Slides server on %s:%d", host, port) | ||
go func() { | ||
if err = s.Start(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
}() | ||
|
||
<-done | ||
log.Print("Stopping Slides server") | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer func() { cancel() }() | ||
if err := s.Shutdown(ctx); err != nil { | ||
return err | ||
} | ||
return err | ||
}, | ||
} | ||
) | ||
<-done | ||
log.Print("Stopping Slides server") | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer func() { cancel() }() | ||
if err := s.Shutdown(ctx); err != nil { | ||
return err | ||
} | ||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
ServeCmd.Flags().StringVar(&keyPath, "keyPath", "slides", "Server private key path") | ||
ServeCmd.Flags().StringVar(&host, "host", "localhost", "Server host to bind to") | ||
ServeCmd.Flags().IntVar(&port, "port", 53531, "Server port to bind to") | ||
ServeCmd.Flags().StringVar(&keyPath, "keyPath", "slides", "Server private key path") | ||
ServeCmd.Flags().StringVar(&host, "host", "localhost", "Server host to bind to") | ||
ServeCmd.Flags().IntVar(&port, "port", 53531, "Server port to bind to") | ||
} |
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 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 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
Oops, something went wrong.