func (s *server) handleHook(t string, payload []byte, altPath string, superUsers []string) {
	if t == "ping" {
		return
	}
	event, err := github.ParseWebHook(t, payload)
	if err != nil {
		log.Printf("- invalid payload for hook %s\n%s", t, payload)
		return
	}
	log.Printf("altPath=%s; superUsers=%s", altPath, strings.Join(superUsers, ","))
	switch e := event.(type) {
	case *github.CommitCommentEvent:
		s.handleCommitComment(e, altPath, superUsers)
	case *github.IssueCommentEvent:
		s.handleIssueComment(e, altPath, superUsers)
	case *github.PullRequestEvent:
		s.handlePullRequest(e, altPath, superUsers)
	case *github.PullRequestReviewCommentEvent:
		s.handlePullRequestReviewComment(e, altPath, superUsers)
	case *github.PushEvent:
		s.handlePush(e, altPath)
	default:
		log.Printf("- ignoring hook type %s", reflect.TypeOf(e).Elem().Name())
	}
}
handleHook handles a validated github webhook.
package main
import (
	"fmt"
	"io"
	"log"
	"net"
	"net/http"
	"net/url"
	"os"
	"reflect"
	"runtime"
	"strings"
	"time"
	"github.com/google/go-github/v31/github"
	fsnotify "gopkg.in/fsnotify.v1"
	"periph.io/x/gohci"
)
func runServer(c *gohci.WorkerConfig, wkr worker, fileName string) error {
	thisFile, err := os.Executable()
	if err != nil {
		return err
	}
	log.Printf("Executable: %s", thisFile)
	log.Printf("Name: %s", c.Name)
	log.Printf("PATH: %s", os.Getenv("PATH"))
	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", c.Port))
	if err != nil {
		return err
	}
	a := ln.Addr().String()
	_ = ln.Close()
	log.Printf("Listening on: %s", a)
	s := &server{c: c, w: wkr, start: time.Now()}
	http.Handle("/", s)
	go http.ListenAndServe(a, nil)
	w, err := fsnotify.NewWatcher()
	if err != nil {
		log.Printf("Failed to initialize watcher: %v", err)
	} else if err = w.Add(thisFile); err != nil {
		log.Printf("Failed to initialize watcher: %v", err)
	} else if err = w.Add(fileName); err != nil {
		log.Printf("Failed to initialize watcher: %v", err)
	}
	_ = SetConsoleTitle(fmt.Sprintf("gohci - %s", a))
	if err == nil {
		select {
		case <-w.Events:
		case err = <-w.Errors:
			log.Printf("Waiting failure: %v", err)
		}
	} else {
		select {}
	}
	s.w.wait()
	return err
}
type server struct {
	c     *gohci.WorkerConfig
	w     worker
	start time.Time
}
func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Printf("%-4s %-21s %s", r.Method, r.RemoteAddr, r.URL.Path)
	defer r.Body.Close()
	if r.URL.Path != "" && r.URL.Path != "/" {
		log.Printf("- Unexpected path %s", r.URL.Path)
		http.NotFound(w, r)
		return
	}
	if r.Method == "HEAD" {
		w.WriteHeader(200)
		return
	}
	if r.Method == "GET" {
		w.Header().Add("Content-Type", "text/plain")
		_, _ = io.WriteString(w, time.Since(s.start).Round(time.Second).String())
		_, _ = io.WriteString(w, "\n")
		_, _ = io.WriteString(w, runtime.Version())
		return
	}
	if r.Method != "POST" {
		http.Error(w, "Invalid method", http.StatusMethodNotAllowed)
		log.Printf("- invalid method %s", r.Method)
		return
	}
	payload, err := github.ValidatePayload(r, []byte(s.c.WebHookSecret))
	if err != nil {
		http.Error(w, "Invalid secret", http.StatusUnauthorized)
		log.Printf("- invalid secret")
		return
	}
	altPath, superUsers, err := validateArgs(r.URL.Query())
	if err != nil {
		log.Printf("Invalid query argument, check your webhook URL: %q; %v", r.URL.String(), err)
		http.Error(w, "Invalid query argument", http.StatusBadRequest)
		return
	}
	s.handleHook(github.WebHookType(r), payload, altPath, superUsers)
	w.Header().Add("Content-Type", "application/json")
	_, _ = io.WriteString(w, "{}")
}