๐Ÿ’พ Archived View for source.community โ€บ ckaznocha โ€บ cliftons-capsule โ€บ blob โ€บ main โ€บ main.go captured on 2023-04-26 at 13:27:57. Gemini links have been rewritten to link to archived content

View Raw

More Information

โฌ…๏ธ Previous capture (2023-01-29)

โžก๏ธ Next capture (2024-02-05)

-=-=-=-=-=-=-

                                                         .
,-. ,-. . . ,-. ,-. ,-.    ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . .
`-. | | | | |   |   |-'    |   | | | | | | | | | | | | | |  | |
`-' `-' `-^ '   `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-|
                                                             /|
                                                            `-'

Profile for ckaznocha

ckaznocha / cliftons-capsule

git clone https://source.community/ckaznocha/cliftons-capsule.git

Branches

Log

Tree

/main.go (main)

โ†‘ /

blob

View raw contents of /main.go (main)

โ”€โ”€โ”€โ”€โ•ฎ
   1โ”‚ package main
   2โ”‚ 
   3โ”‚ import (
   4โ”‚ 	"context"
   5โ”‚ 	"crypto/tls"
   6โ”‚ 	"embed"
   7โ”‚ 	"flag"
   8โ”‚ 	"fmt"
   9โ”‚ 	"log"
  10โ”‚ 	"os"
  11โ”‚ 	"os/signal"
  12โ”‚ 
  13โ”‚ 	"source.community/ckaznocha/gemini"
  14โ”‚ )
  15โ”‚ 
  16โ”‚ //go:embed templates
  17โ”‚ var templateFS embed.FS
  18โ”‚ 
  19โ”‚ func main() {
  20โ”‚ 	logger := log.New(os.Stdout, "[Gemini Capsule] ", log.LstdFlags)
  21โ”‚ 
  22โ”‚ 	cert := flag.String("tls_cert", "cert.pem", "path to the tls cert file")
  23โ”‚ 	key := flag.String("tls_key", "key.pem", "path to the tls key file")
  24โ”‚ 	addr := flag.String("listen_addr", ":1965", "address to listen on")
  25โ”‚ 	assets := flag.String("assets", "assets", "path to assets dir")
  26โ”‚ 	flag.Parse()
  27โ”‚ 
  28โ”‚ 	logger.Println("Server starting")
  29โ”‚ 
  30โ”‚ 	app, err := newApp(logger, os.DirFS(*assets), templateFS)
  31โ”‚ 	if err != nil {
  32โ”‚ 		logger.Fatal(err)
  33โ”‚ 	}
  34โ”‚ 
  35โ”‚ 	mux := gemini.NewServeMux()
  36โ”‚ 	mux.HandleFunc("/", app.indexHandler)
  37โ”‚ 	mux.HandleFunc("/gemlog", app.gemlogHandler)
  38โ”‚ 
  39โ”‚ 	s := &gemini.Server{
  40โ”‚ 		Handler: mux,
  41โ”‚ 		LogHandler: func(message string, isError bool) {
  42โ”‚ 			if isError {
  43โ”‚ 				logger.Printf("gemini server: %s", message)
  44โ”‚ 			}
  45โ”‚ 		},
  46โ”‚ 		TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12},
  47โ”‚ 	}
  48โ”‚ 
  49โ”‚ 	s.RegisterOnShutdown(func() {
  50โ”‚ 		s.LogHandler("shutting down", false)
  51โ”‚ 	})
  52โ”‚ 
  53โ”‚ 	ctx, cancel := context.WithCancel(context.Background())
  54โ”‚ 	defer cancel()
  55โ”‚ 
  56โ”‚ 	logger.Println("Server started")
  57โ”‚ 
  58โ”‚ 	go func() {
  59โ”‚ 		defer cancel()
  60โ”‚ 
  61โ”‚ 		s.LogHandler("starting", false)
  62โ”‚ 		err := s.ListenAndServeTLS(*addr, *cert, *key)
  63โ”‚ 		s.LogHandler(fmt.Sprintf("exited: %s\n", err), true)
  64โ”‚ 	}()
  65โ”‚ 
  66โ”‚ 	ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
  67โ”‚ 	defer stop()
  68โ”‚ 
  69โ”‚ 	<-ctx.Done()
  70โ”‚ 
  71โ”‚ 	fmt.Fprint(logger.Writer(), "\n")
  72โ”‚ 
  73โ”‚ 	logger.Println("Shutdown starting")
  74โ”‚ 	defer logger.Println("Shutdown complete")
  75โ”‚ 
  76โ”‚ 	if err := s.Shutdown(context.Background()); err != nil {
  77โ”‚ 		logger.Printf("Error during shutdown: %s\n", err)
  78โ”‚ 	}
  79โ”‚ }
โ”€โ”€โ”€โ”€โ•ฏ

ยท ยท ยท

๐Ÿก Home

FAQs

Privacy Policy

Terms & Conditions

Official Gemlog

info@source.community

ยฉ 2023 source.community