Skip to content

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Aug 27, 2023
1 parent d86c240 commit 4940f5c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 59 deletions.
5 changes: 0 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (c *Client) Do(r *Request) (*Response, error) {
req.Header.Add(name, value)
}
}

resp, err := c.Doer.Do(req)
if err != nil {
return nil, err
Expand All @@ -143,16 +142,13 @@ func (c *Client) Do(r *Request) (*Response, error) {
return nil, HTTPError{URL: link, RequestError: err, StatusCode: resp.StatusCode}
}
defer resp.Body.Close()

var reader = resp.Body

// Detect compressed response.
reader, err = maybeCompressed(reader)
if err != nil {
return nil, err
}
defer reader.Close()

if r.CleanBeforeDecode {
// Remove some chars, that the XML decoder will complain about.
b, err := ioutil.ReadAll(reader)
Expand All @@ -161,7 +157,6 @@ func (c *Client) Do(r *Request) (*Response, error) {
}
reader = ioutil.NopCloser(strings.NewReader(ControlCharReplacer.Replace(string(b))))
}

// Drain response XML, iterate over various XML encoding declarations.
// Limit the amount we can read.
respBody, err := ioutil.ReadAll(io.LimitReader(reader, 2<<24))
Expand Down
5 changes: 0 additions & 5 deletions cmd/metha-files/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,20 @@ var (
)

func main() {

flag.Parse()

if *version {
fmt.Println(metha.Version)
os.Exit(0)
}

if flag.NArg() == 0 {
log.Fatal("endpoint required")
}

metha.BaseDir = *baseDir
harvest := metha.Harvest{
BaseURL: metha.PrependSchema(flag.Arg(0)),
Format: *format,
Set: *set,
}

for _, fn := range harvest.Files() {
fmt.Println(fn)
}
Expand Down
9 changes: 0 additions & 9 deletions cmd/metha-fortune/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func createSearcher(endpoint string) Search {
log.Printf("estimated probability of record: 1/%d", events)
}
rid := ids[rand.Intn(len(ids))]

req = metha.Request{
BaseURL: endpoint,
Verb: "GetRecord",
Expand Down Expand Up @@ -181,32 +180,24 @@ func createSearcher(endpoint string) Search {
func main() {
rand.Seed(time.Now().UnixNano())
flag.Parse()

if !*debug {
log.SetOutput(ioutil.Discard)
}

ctx, cancel := context.WithTimeout(context.Background(), *timeout)
defer cancel()

var searchers []Search
for i := 0; i < *k; i++ {
searchers = append(searchers, createSearcher(metha.RandomEndpoint()))
}

s := spinner.New(spinner.CharSets[25], 100*time.Millisecond)
s.Writer = os.Stderr

if !*debug {
s.Start()
}

result := First(ctx, searchers...)

if !*debug {
s.Stop()
}

if result.Err != nil || result.Fortune == "" {
fmt.Printf("No fortune available at this time.\n")
if *debug {
Expand Down
18 changes: 6 additions & 12 deletions cmd/metha-id/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,25 @@ import (
var version = flag.Bool("v", false, "show version")

func main() {

flag.Parse()

if *version {
fmt.Println(metha.Version)
os.Exit(0)
}

if flag.NArg() == 0 {
log.Fatalf("An endpoint URL is required, maybe try: %s", metha.RandomEndpoint())
}

baseURL := metha.PrependSchema(flag.Arg(0))
repo := metha.Repository{BaseURL: baseURL}

m := make(map[string]interface{})

req := metha.Request{Verb: "Identify", BaseURL: baseURL}
var (
baseURL = metha.PrependSchema(flag.Arg(0))
repo = metha.Repository{BaseURL: baseURL}
m = make(map[string]interface{})
req = metha.Request{Verb: "Identify", BaseURL: baseURL}
)
resp, err := metha.StdClient.Do(&req)
if err != nil {
log.Fatal(err)
}
m["identify"] = resp.Identify

if formats, err := repo.Formats(); err == nil {
m["formats"] = formats
} else {
Expand All @@ -47,7 +42,6 @@ func main() {
} else {
log.Println(err)
}

if err := json.NewEncoder(os.Stdout).Encode(m); err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/metha-ls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ func ellipsis(s string, length int) string {

func main() {
flag.Parse()

files, err := ioutil.ReadDir(metha.GetBaseDir())
if err != nil {
log.Fatal(err)
}

for _, file := range files {
b, err := base64.RawURLEncoding.DecodeString(file.Name())
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions copyhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewCopyHook(w io.Writer, levels ...log.Level) CopyHook {
ch := CopyHook{
Writer: w,
}

if len(levels) > 0 {
ch.levels = levels
} else {
Expand All @@ -30,7 +29,6 @@ func NewCopyHook(w io.Writer, levels ...log.Level) CopyHook {
log.PanicLevel,
}
}

return ch
}

Expand All @@ -45,13 +43,11 @@ func (hook CopyHook) Fire(entry *log.Entry) error {
if err != nil {
return err
}

for _, l := range hook.levels {
if l == entry.Level {
_, err := hook.Write([]byte(line))
return err
}
}

return nil
}
20 changes: 10 additions & 10 deletions extra/pkpindex/pkpindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
//
// Output will json lines (oai endpoint is guessed):
//
// {
// "name": "Scholarly and Research Communication",
// "homepage": "http://src-online.ca/index.php/src",
// "oai": "http://src-online.ca/index.php/src/oai"
// }
// {
// "name": "Stream: Culture/Politics/Technology",
// "homepage": "http://journals.sfu.ca/stream/index.php/stream",
// "oai": "http://journals.sfu.ca/stream/index.php/stream/oai"
// }
// {
// "name": "Scholarly and Research Communication",
// "homepage": "http://src-online.ca/index.php/src",
// "oai": "http://src-online.ca/index.php/src/oai"
// }
// {
// "name": "Stream: Culture/Politics/Technology",
// "homepage": "http://journals.sfu.ca/stream/index.php/stream",
// "oai": "http://journals.sfu.ca/stream/index.php/stream/oai"
// }
//
// Additional ideas:
//
Expand Down
5 changes: 0 additions & 5 deletions fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,24 @@ func MustGlob(pattern string) []string {
// destination file.
func MoveCompressFile(src, dst string) (err error) {
tmp := fmt.Sprintf("%s-tmp-%d", dst, rand.Intn(999999999))

f, err := os.Create(tmp)
if err != nil {
return err
}
defer f.Close()

gw := gzip.NewWriter(f)
defer gw.Close()

ff, err := os.Open(src)
if err != nil {
return err
}
defer ff.Close()

if _, err := io.Copy(gw, ff); err != nil {
return err
}
if err := os.Rename(tmp, dst); err != nil {
return err
}

return os.Remove(src)
}

Expand Down
4 changes: 0 additions & 4 deletions intervals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestDailyIntervals(t *testing.T) {
},
},
}

for _, c := range cases {
r := c.Interval.DailyIntervals()
if len(r) != len(c.Result) {
Expand All @@ -51,7 +50,6 @@ func TestDailyIntervals(t *testing.T) {
}
}
}

}

func TestHourlyIntervals(t *testing.T) {
Expand Down Expand Up @@ -80,7 +78,6 @@ func TestHourlyIntervals(t *testing.T) {
},
},
}

for _, c := range cases {
r := c.Interval.HourlyIntervals()
if len(r) != len(c.Result) {
Expand All @@ -92,5 +89,4 @@ func TestHourlyIntervals(t *testing.T) {
}
}
}

}
8 changes: 5 additions & 3 deletions laster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ func (l DirLaster) Last() (string, error) {
if err != nil {
return "", err
}
var values []string
var (
values []string
v string
)
for _, fi := range files {
v := l.ExtractorFunc(fi)
if v != "" {
if v = l.ExtractorFunc(fi); v != "" {
values = append(values, v)
}
}
Expand Down

0 comments on commit 4940f5c

Please sign in to comment.