send-over-http

Share a file with someone on your local network using QR Code
git clone git://git.server.ky/slackcoder/send-over-http
Log | Files | Refs | README

qr_code.go (754B)


      1 package sendoverhttp
      2 
      3 import (
      4 	"fmt"
      5 	"os"
      6 
      7 	"github.com/mdp/qrterminal/v3"
      8 	_ "github.com/mdp/qrterminal/v3"
      9 )
     10 
     11 type TerminalQRShower struct {
     12 	waiter *Waiter
     13 	str    string
     14 }
     15 
     16 func NewTerminalQRShower(str string) *TerminalQRShower {
     17 	return &TerminalQRShower{
     18 		waiter: NewWaiter(),
     19 		str:    str,
     20 	}
     21 }
     22 
     23 // Start the run, returning any error which occurs from start to
     24 // finish.
     25 func (s *TerminalQRShower) Start() error {
     26 	qrterminal.Generate(s.str, qrterminal.L, os.Stdout)
     27 	fmt.Println()
     28 	fmt.Printf("Hosting file at %s", s.str)
     29 	fmt.Println()
     30 	fmt.Println()
     31 	s.waiter.Wait()
     32 	return nil
     33 }
     34 
     35 // Stop the run and wait until it has ended.  It can be called multiple
     36 // times, ending immediately.
     37 func (s *TerminalQRShower) Stop() {
     38 	s.waiter.Stop()
     39 }