ctftime

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanDescription

func CleanDescription(description string) string

CleanDescription takes in a string and removes any unnecessary new lines and ensures that the string is no longer than 1024 characters.

desc := "This is a long\ndescription\nwith\nmultiple\nlines."
cleanDesc := CleanDescription(desc)

func IsActive added in v0.1.10

func IsActive(event Event) bool

IsActive takes in an Event and returns whether the event is currently active or not based on the current time. It compares the start and finish time of the event with the current time.

event := Event{
	Start: time.Now().Add(-1 * time.Hour),
	Finish: time.Now().Add(1 * time.Hour),
}
fmt.Println(IsActive(event)) // Output: true

Types

type CTFTeam added in v0.1.10

type CTFTeam struct {
	ID           int      `json:"id"`
	Academic     bool     `json:"academic"`
	PrimaryAlias string   `json:"primary_alias"`
	Name         string   `json:"name"`
	Country      string   `json:"country"`
	Aliases      []string `json:"aliases"`
	Rating       map[string]struct {
		RatingPlace     int     `json:"rating_place"`
		OrganizerPoints float64 `json:"organizer_points"`
		RatingPoints    float64 `json:"rating_points"`
		CountryPlace    int     `json:"country_place"`
	} `json:"rating"`
}

Struct for API Endpoint ctftime.org/api/v1/teams/

func GetCTFTeam

func GetCTFTeam(id int) (CTFTeam, error)

GetCTFTeam takes in an id and returns a CTFTeam struct, along with any error that may have occurred. The function uses the ctftimeURL to make a GET request to the API and retrieve the team information by id. The response body is then parsed into a CTFTeam struct using json.Unmarshal.

team, err := GetCTFTeam(1)
if err != nil {
	fmt.Println(err)
}

type Event

type Event struct {
	ID            uint64    `json:"id"`
	CTFID         int       `json:"ctf_id"`
	Title         string    `json:"title"`
	Description   string    `json:"description"`
	URL           string    `json:"url"`
	Weight        float64   `json:"weight"`
	Onsite        bool      `json:"onsite"`
	Location      string    `json:"location"`
	Restrictions  string    `json:"restrictions"`
	Format        string    `json:"format"`
	FormatID      int       `json:"format_id"`
	Participants  int       `json:"participants"`
	CTFTimeURL    string    `json:"ctftime_url"`
	LiveFeed      string    `json:"live_feed"`
	IsVotableNow  bool      `json:"is_votable_now"`
	PublicVotable bool      `json:"public_votable"`
	Start         time.Time `json:"start"`
	Finish        time.Time `json:"finish"`
}

Struct for API Endpoint ctftime.org/api/v1/events/

func CleanCTFEvents

func CleanCTFEvents(events []Event) ([]Event, error)

CleanCTFEvents takes in a slice of Event structs and performs several clean up operations on the slice. Title and Description fields of each event are trimmed and cleaned. Events that have finished are removed from the slice. The remaining events are sorted into two slices: active events and upcoming events. Active events are sorted by finish time, and upcoming events are sorted by start time. The two slices are then combined and returned, along with any error that may have occurred.

ctfEvents, err := CleanCTFEvents(events)
if err != nil {
	fmt.Println(err)
}

func GetCTFEvent

func GetCTFEvent(id int) (Event, error)

GetCTFEvent takes in an integer 'id' and returns an Event struct, along with any error that may have occurred. The function uses an http client to send a GET request to the ctftime API with the provided id, and parses the response body into an Event struct.

event, err := GetCTFEvent(1)
if err != nil {
	fmt.Println(err)
}

func GetCTFEvents

func GetCTFEvents() ([]Event, error)

GetCTFEvents retrieves CTF events from the ctftime API within the next 180 days. The events are unmarshaled from json and cleaned before being returned.

events, err := GetCTFEvents()
if err != nil {
	fmt.Println(err)
}

type TopTeam added in v0.0.2

type TopTeam struct {
	TeamName string  `json:"team_name"`
	Points   float64 `json:"points"`
	TeamID   int     `json:"team_id"`
}

func GetTopTeams added in v0.0.2

func GetTopTeams() ([]TopTeam, error)

Get the top teams on CTFTime

type TopTeams added in v0.0.2

type TopTeams struct {
	Teams []TopTeam `json:"2022"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL