Projects STRLCPY wb Commits e9c51b3d
🤬
  • ■ ■ ■ ■ ■
    README.md
    1  -<h1>wb</h1>
     1 +<h1> wb</h1>
    2 2  <p> A wizard who goes back and brings old files!</p>
    3 3  <p>
    4 4   <a href="https://opensource.org/licenses/MIT">
    5 5   <img src="https://img.shields.io/badge/license-MIT-_red.svg">
    6  - </a>
    7 6   <a href="https://goreportcard.com/badge/github.com/riza/wb">
    8 7   <img src="https://goreportcard.com/badge/github.com/riza/wb">
    9 8   </a>
    skipped 30 lines
  • ■ ■ ■ ■ ■ ■
    go.mod
    1 1  module github.com/riza/wb
     2 + 
     3 +go 1.19
     4 + 
     5 +require (
     6 + github.com/sirupsen/logrus v1.9.0 // indirect
     7 + go.uber.org/atomic v1.10.0 // indirect
     8 + go.uber.org/multierr v1.8.0 // indirect
     9 + go.uber.org/zap v1.23.0 // indirect
     10 + golang.org/x/sys v0.1.0 // indirect
     11 +)
     12 + 
  • ■ ■ ■ ■ ■ ■
    go.sum
     1 +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
     2 +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
     3 +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
     4 +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
     5 +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
     6 +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
     7 +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
     8 +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
     9 +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
     10 +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
     11 +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
     12 +go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
     13 +go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
     14 +go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
     15 +go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
     16 +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
     17 +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
     18 +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
     19 +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
     20 +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
     21 +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
     22 + 
  • ■ ■ ■ ■ ■ ■
    main.go
    skipped 5 lines
    6 6   "errors"
    7 7   "flag"
    8 8   "fmt"
     9 + log "github.com/sirupsen/logrus"
    9 10   "io"
    10 11   "net/http"
    11 12   "os"
    skipped 19 lines
    31 32   }
    32 33   
    33 34   if err := sc.Err(); err != nil {
    34  - fmt.Fprintf(os.Stderr, "failed to read input: %s\n", err)
     35 + log.Errorf("failed to read input: %s\n", err)
    35 36   }
    36 37   }
    37 38   
    skipped 3 lines
    41 42   
    42 43   snapshots, err := getSnapshots(client, url)
    43 44   if err != nil {
    44  - fmt.Fprintf(os.Stderr, "failed to getting snapshots %s\n", err)
     45 + log.Errorf("failed to snapshots: %s\n", err)
    45 46   }
    46 47   
    47 48   lastSnapshot := snapshots[len(snapshots)-1]
    48  - lastSnapshotTs := lastSnapshot[0]
    49  - lastSnapshotURL := lastSnapshot[1]
    50  - 
    51  - request, err := http.NewRequest("GET", fmt.Sprintf(wbFileURL, lastSnapshotTs, lastSnapshotURL), nil)
    52  - if err != nil {
    53  - fmt.Fprintf(os.Stderr, "failed to generate request waybackmachine api: %s\n", err)
    54  - }
    55  - 
    56  - request.Header.Add("Accept-Encoding", "plain")
    57  - 
    58  - response, err := client.Do(request)
     49 + snapshotContent, err := getSnapshotContent(client, lastSnapshot[0], lastSnapshot[1])
    59 50   if err != nil {
    60  - fmt.Fprintf(os.Stderr, "failed to send request waybackmachine api: %s\n", err)
     51 + log.Fatalf("failed to read input: %s\n", err)
    61 52   }
    62 53   
    63  - defer response.Body.Close()
    64  - 
    65  - io.Copy(os.Stdout, response.Body)
     54 + io.Copy(os.Stdout, snapshotContent)
    66 55  }
    67 56   
    68 57  func getSnapshots(c http.Client, url string) ([][]string, error) {
    skipped 23 lines
    92 81   return r[1:], nil
    93 82  }
    94 83   
     84 +func getSnapshotContent(c http.Client, ts, url string) (io.ReadCloser, error) {
     85 + request, err := http.NewRequest("GET", fmt.Sprintf(wbFileURL, ts, url), nil)
     86 + if err != nil {
     87 + return nil, fmt.Errorf("getSnapshotContent: failed to generate request waybackmachine api: %w", err)
     88 + }
     89 + 
     90 + request.Header.Add("Accept-Encoding", "plain")
     91 + 
     92 + response, err := c.Do(request)
     93 + if err != nil {
     94 + return nil, fmt.Errorf("getSnapshotContent: failed to send request waybackmachine api: %w", err)
     95 + }
     96 + defer response.Body.Close()
     97 + 
     98 + return response.Body, nil
     99 +}
     100 + 
Please wait...
Page is in error, reload to recover