webhandlers

Imports

Imports #

"advent2024/pkg/solver"
"advent2024/web/config"
"advent2024/web/middleware"
"advent2024/web/weberrors"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"reflect"
"strings"
"text/template"

Functions

FieldNames function #

extract field names from struct helper functions for templates

func FieldNames(v interface{}) []string

GetField function #

extracts value of field from struct helper functions for templates

func GetField(v interface{}, name string) interface{}

HealthCheck function #

Handles healthcheck page

func HealthCheck(w http.ResponseWriter, r *http.Request)

OAuthCallback function #

Handles callback redirects from OAuth providers Pulls data about OAuth provider from config Renders page from template, with information pulled from configuration

func OAuthCallback(w http.ResponseWriter, r *http.Request)

OAuthHandler function #

Handles user code<>token exchange page TODO: implement more providers, curently only github gets OAuth code from client, exchanges code for token with provider and then generates JWT token for client

func OAuthHandler(w http.ResponseWriter, r *http.Request)

ServerDocs function #

Handles documentation page Renders page from template, with information pulled from configuration

func ServerDocs(w http.ResponseWriter, r *http.Request)

ServerIndex function #

Handles main page Renders page from template, with information pulled from configuration TODO: refactor to be usable for all simple pages

func ServerIndex(w http.ResponseWriter, r *http.Request)

ServerStatus function #

Handles server status page. Output including hostname and list of registered solvers

func ServerStatus(w http.ResponseWriter, r *http.Request)

SolverListing function #

Handles display of registered solvers

func SolverListing(w http.ResponseWriter, r *http.Request)

exchangeCodeForToken function #

Exchanges code with OAuth provider for a token

func exchangeCodeForToken(provider *config.OAuthProvider, code string) (middleware.OAuthResponse, error)