Skip to main content

Featured

Week 12: Release 0.4 Part: 3

Release 0.4 Part 3 This is going to be my final post for this class which covers my final update on my Release 0.4. Earlier this week I made a PR that ports SearchBar to NextJS but I'm still waiting for it to be reviewed some more. I've had some feedback that I have implemented and have also requested a review again. Overall this Release went pretty smoothly for the actually GitHub side of things like setting up the issue, making the PR, and so on. In Release 0.3 I wasn't so certain on how this process happened with Telescope, but now I never had these issues for 0.4. Issue #1470 Fix #1470: Port SearchBar from Gatsby -> NextJS #1503 Did I Meet My Goals? Going into this release I had two main goals: 1. Setup the Issue/PR with no issues 2. Learn about NextJS I feel like I meet both of these goals at the end. I had no issues setting up my branch, updating my master, making the issue, making the PR, and following through on review comments so far. When it comes to learning m

Week 7: Lab 6: Starting with Telescope and using Gist

 The Lab

This weeks lab was all about starting to learn how to work with Telescope and to setup its development environment. I also learned how to make a gist and use the diff command.

Setting up Telescopes environment was a real struggle. There is just so many moving parts going into the project that it was quite a task to get it running, though I'm still not quite sure if I got it running correctly. I ended setting up Redis Server and Elastic Search locally on my machine. Elastic Search seems to be working correctly since I was able to access the blog feeds, but I'm still not too sure about Redis.

Changing my LinkStatus program

I actually needed to put in a lot of changes to get the program to work with telescope. I added a new command that would start the whole telescope process called "-t". Using ./LinkStatus http://localhost:3000/posts -t would access the 10 most recent blog URLs and convert them into a JSON file. I then setup a struct to hold this data so I could then parse and format it into a proper URL into a another new file. With this I could use my program normally without many changes besides a new regex pattern to look for localhost URLs.

Here's the new Telescope output:


Since I had access to the JSON format for the blog data (id, URL) I choose to construct the URLs since each of them followed a similar pattern. I simply just appended "/posts/url" onto a premade string and appending that data to a file. The function completed a few important tasks:

  • Create a JSON file
  • Perform a Get request on localhost:3000
  • Read and pull all the JSON data into the file
  • Create an object of type Telescope to hold the id and URL values
  • Populate that object with the data using Unmarshal
  • Create a new text file
  • Write to the new text file a constructed URL using the URL value

Here's the new Struct and the new function to make this all work:

//Telescope struct which lays out the json data for easy storage
type Telescope struct {
    ID  string `json:"id"`
    URL string `json:"url"`
}
func telescopeParse(file string) {
    fmt.Println("Telescope Parsing")
    fmt.Println(file)
    fmt.Println("----------------------------------------------------------------------------------")
    //Get the json data in a file
    out_ := os.OpenFile("telescopeData.json", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    defer out.Close()
    resperr := http.Get(file)
    if err != nil {
        log.Println(err)
    }
    defer resp.Body.Close()
    _err = io.Copy(out, resp.Body)
    if err != nil {
        log.Println(err)
    }
    jsonFileerr := os.Open("telescopeData.json")
    if err != nil {
        fmt.Println(err)
    }
    byteValueerr := ioutil.ReadAll(jsonFile)
    if err != nil {
        fmt.Println(err)
    }
    var teleData []Telescope
    err = json.Unmarshal(byteValue, &teleData)
    if err != nil {
        fmt.Println(err)
    }
    telescopeFileerr := os.OpenFile("tData.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    if err != nil {
        log.Fatal(err)
    }
    for i := 0; i < len(teleData); i++ {
        telescopeFile.Write([]byte("http://localhost:3000" + teleData[i].URL + " "))
    }
    telescopeFile.Close()
    jsonFile.Close()
}

Since I'm new to working with GO, I had to research quite a bit on how to work with JSON data for this lab. I ended up using the encoding/json package to work with the data and it went pretty well.

With a newly created file in hand the program works as normal, but a some additional of a new regex pattern in file.go was introduced to handle localhost URLs.

if telescope == true {
        re = regexp.MustCompile(`https?:\/\/localhost:[0-9]{1,5}\/([-a-zA-Z0-9()@:%_\+.~#?&\/=]*)`)
    }

Using Gist and Diff

Once my work was finishing I had to create a gist to easily share my work. I added my two files I worked on then started to think how to use the diff command. At first I thought maybe download for gist with old and new files to then run the command, but after searching up the diff command docs I found out how to specify branches. From here I used git diff telescope master -- main.go.

I ran this command on both my files and added it to my gist.

What's Next?

Over the course of this weekend and the next week Im going to be working with Telescope to finish my release 0.3 assignment. I already went out and got assigned for an issue to solve, so now I can focus on learning how to work with and solve this issue.

The issue I decided to work on was to add an additional feature to the search bar. I would need to make the program support autocomplete on the authors name as you would be typing and have them come up underneath the search bar. Add autocomplete to search for Authors #1260


Comments

Popular Posts