<commit_before>package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"path"
	"strings"
)

type Token struct {
	T string `json:"token"`
}

func (t *Token) Init(user, pass string) error {
	req, err := http.NewRequest(
		"POST",
		"https://api.github.com/authorizations",
		strings.NewReader(`{"note":"gfm-viewer"}`),
	)
	if err != nil {
		return err
	}
	req.SetBasicAuth(user, pass)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode/100 != 2 {
		body, _ := ioutil.ReadAll(res.Body)
		return fmt.Errorf(string(body))
	}

	json.NewDecoder(res.Body).Decode(t)
	return t.SaveFile()
}

func (t *Token) SaveFile() error {
	return ioutil.WriteFile(t.filePath(), []byte(t.T), 0644)
}

func (_ *Token) filePath() string {
	fname := "gfm-viewer"
	if xdg := os.Getenv("XDG_CACHE_HOME"); xdg != "" {
		return path.Join(xdg, fname)
	} else {
		return path.Join(os.Getenv("HOME"), ".cache", fname)
	}
}

func (t *Token) RoundTrip(req *http.Request) (*http.Response, error) {
	req.Header.Set("Authorization", "token "+t.T)

	return http.DefaultTransport.RoundTrip(req)
}<commit_msg>Implement LoadFile and hasToken method<commit_after>package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"path"
	"strings"
)

type Token struct {
	T string `json:"token"`
}

func (t *Token) Init(user, pass string) error {
	req, err := http.NewRequest(
		"POST",
		"https://api.github.com/authorizations",
		strings.NewReader(`{"note":"gfm-viewer"}`),
	)
	if err != nil {
		return err
	}
	req.SetBasicAuth(user, pass)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode/100 != 2 {
		body, _ := ioutil.ReadAll(res.Body)
		return fmt.Errorf(string(body))
	}

	json.NewDecoder(res.Body).Decode(t)
	return t.SaveFile()
}

func (t *Token) SaveFile() error {
	return ioutil.WriteFile(t.filePath(), []byte(t.T), 0644)
}

func (t *Token) LoadFile() error {
	f, err := ioutil.ReadFile(t.filePath())
	if err != nil {
		return err
	}
	t.T = string(f)
	return nil
}

func (t *Token) hasToken() bool {
	err := t.LoadFile()
	if err != nil {
		return false
	}
	return t.T != ""
}

func (_ *Token) filePath() string {
	fname := "gfm-viewer"
	if xdg := os.Getenv("XDG_CACHE_HOME"); xdg != "" {
		return path.Join(xdg, fname)
	} else {
		return path.Join(os.Getenv("HOME"), ".cache", fname)
	}
}

func (t *Token) RoundTrip(req *http.Request) (*http.Response, error) {
	req.Header.Set("Authorization", "token "+t.T)

	return http.DefaultTransport.RoundTrip(req)
}
{'fraction_non_alphanumeric': 0.18269602162997295, 'fraction_numerical': 0.006179992275009656, 'mean_word_length': 3.9903660886319847, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3325676', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1045, 'n_words': 225}