leetinfo

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 2 Imported by: 0

README

leetinfo

A Go library to fetch LeetCode profile insights via LeetCode's public GraphQL API.

CI Go Reference Go Version


Overview

leetinfo gives you a clean Go API over LeetCode's public GraphQL endpoint to pull profile, submission, and streak data without building the query or parsing the response yourself. No API token is required — the endpoint serves public profile data.

Function What it returns
GetUser Full profile: question counts, profile info, submission stats, recent submissions, streak
GetStreak Current and longest daily-submission streaks
GetSubmitStats Accepted vs. total submissions grouped by difficulty
GetRecentSubmissions The user's most recent submissions

Installation

go get github.com/reinanbr/leetinfo

Requirements: Go 1.21+ · Internet access to leetcode.com/graphql


Quick Start

package main

import (
    "fmt"

    "github.com/reinanbr/leetinfo"
)

func main() {
    user := "reinanbr"

    data, _ := leetinfo.GetUser(user)
    fmt.Println("ranking:", data.MatchedUser.Profile.Ranking)
    fmt.Println("current streak:", data.MatchedUser.Streak.CurrentStreak)

    streak, _ := leetinfo.GetStreak(user)
    fmt.Println("longest streak:", streak.LongestStreak)

    stats, _ := leetinfo.GetSubmitStats(user)
    fmt.Println("accepted (easy):", stats.AcSubmissionNum[0].Count)

    recent, _ := leetinfo.GetRecentSubmissions(user)
    fmt.Println("recent submissions:", len(recent))
}

API Reference

GetUser(username string) (UserData, error)

Returns the full profile payload for a username: available question counts by difficulty, profile info, submission stats, recent submissions, and a computed submission streak.

data, err := leetinfo.GetUser("reinanbr")
if err != nil {
    log.Fatal(err)
}
fmt.Println(data.MatchedUser.Username, data.MatchedUser.Profile.Ranking)

Response type:

type UserData struct {
    AllQuestionsCount    []QuestionCount
    MatchedUser          MatchedUser
    RecentSubmissionList []Submission
}

type MatchedUser struct {
    Username           string
    FirstName          string
    LastName            string
    Contributions       Contributions
    Profile             Profile
    SubmissionCalendar  string
    SubmitStats         SubmitStats
    Streak              StreakStats
}

Returns an error if the username doesn't exist on LeetCode.


GetStreak(username string) (StreakStats, error)

Returns the user's current and longest daily-submission streaks, computed from their public submission calendar. The current streak is zero if the user hasn't submitted anything today.

streak, err := leetinfo.GetStreak("reinanbr")

fmt.Println("current:", streak.CurrentStreak)
fmt.Println("longest:", streak.LongestStreak)
fmt.Println("total submissions:", streak.TotalSubmissions)

Response type:

type StreakStats struct {
    TotalSubmissions int
    CurrentStreak    int
    LongestStreak    int
}

GetSubmitStats(username string) (SubmitStats, error)

Returns accepted vs. total submission counts grouped by difficulty.

stats, err := leetinfo.GetSubmitStats("reinanbr")

for _, s := range stats.AcSubmissionNum {
    fmt.Printf("%s: %d/%d\n", s.Difficulty, s.Count, s.Submissions)
}

Response type:

type SubmitStats struct {
    AcSubmissionNum    []SubmissionStat
    TotalSubmissionNum []SubmissionStat
}

type SubmissionStat struct {
    Difficulty  string
    Count       int
    Submissions int
}

GetRecentSubmissions(username string) ([]Submission, error)

Returns the user's most recent submissions (title, language, status, timestamp).

submissions, err := leetinfo.GetRecentSubmissions("reinanbr")

for _, s := range submissions {
    fmt.Printf("%s (%s) - %s\n", s.Title, s.Lang, s.StatusDisplay)
}

Response type:

type Submission struct {
    Title         string
    TitleSlug     string
    Timestamp     string
    StatusDisplay string
    Lang          string
}

Testing

Tests are integration tests that hit the live LeetCode API — no token needed, just internet access.

# Run all tests
go test -v

# Run a specific test
go test -v -run TestGetUser

Smoke Test CLI

A CLI at cmd/smoke validates all endpoints end-to-end before you publish or deploy.

go run ./cmd/smoke -user reinanbr
Flag Description Default
-user LeetCode username (required)

Notes

  • Responses depend on LeetCode's API availability; unauthenticated requests may be rate-limited.
  • GetStreak, GetSubmitStats, and GetRecentSubmissions each call GetUser internally — if you need more than one of these for the same user, call GetUser once and read the fields directly to save a round trip.

License

MIT © reinanbr

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contributions

type Contributions = utils.Contributions

type MatchedUser

type MatchedUser = utils.MatchedUser

type Profile

type Profile = utils.Profile

type QuestionCount

type QuestionCount = utils.QuestionCount

type StreakStats

type StreakStats = utils.StreakStats

func GetStreak

func GetStreak(username string) (StreakStats, error)

GetStreak returns the user's current and longest daily-submission streaks, derived from their public submission calendar.

Example
package main

import (
	"fmt"

	"github.com/reinanbr/leetinfo"
)

func main() {
	result, err := leetinfo.GetStreak("reinanbr")
	if err != nil {
		fmt.Println("error:", err)
		return
	}

	fmt.Println(result.LongestStreak >= 0)
	fmt.Println(result.CurrentStreak >= 0)
}
Output:
true
true

type Submission

type Submission = utils.Submission

func GetRecentSubmissions

func GetRecentSubmissions(username string) ([]Submission, error)

GetRecentSubmissions returns the user's most recent submissions.

type SubmissionStat

type SubmissionStat = utils.SubmissionStat

type SubmitStats

type SubmitStats = utils.SubmitStats

func GetSubmitStats

func GetSubmitStats(username string) (SubmitStats, error)

GetSubmitStats returns accepted vs. total submission counts grouped by difficulty.

Example
package main

import (
	"fmt"

	"github.com/reinanbr/leetinfo"
)

func main() {
	result, err := leetinfo.GetSubmitStats("reinanbr")
	if err != nil {
		fmt.Println("error:", err)
		return
	}

	fmt.Println(len(result.AcSubmissionNum) > 0)
}
Output:
true

type UserData

type UserData = utils.UserData

func GetUser

func GetUser(username string) (UserData, error)

GetUser fetches the full LeetCode profile for username: available question counts by difficulty, profile info, submission stats, recent submissions, and a computed submission streak.

Example
package main

import (
	"fmt"

	"github.com/reinanbr/leetinfo"
)

func main() {
	result, err := leetinfo.GetUser("reinanbr")
	if err != nil {
		fmt.Println("error:", err)
		return
	}

	fmt.Println(result.MatchedUser.Username != "")
	fmt.Println(len(result.AllQuestionsCount) > 0)
}
Output:
true
true

Directories

Path Synopsis
cmd
smoke command
examples
user command
internal

Jump to

Keyboard shortcuts

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