<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yang Lyu on Medium]]></title>
        <description><![CDATA[Stories by Yang Lyu on Medium]]></description>
        <link>https://medium.com/@yanglyu5201?source=rss-1f727e3428da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YT1WC4uZFjW0Fd_ZOvk6AA.png</url>
            <title>Stories by Yang Lyu on Medium</title>
            <link>https://medium.com/@yanglyu5201?source=rss-1f727e3428da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:39:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yanglyu5201/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Review of Rob Pike’s GopherConAu talk at end of 2023, what we got right and wrong of golang]]></title>
            <link>https://medium.com/@yanglyu5201/review-of-rob-pikes-gopherconau-talk-at-end-of-2023-what-we-got-right-and-wrong-of-golang-e5a30646539d?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5a30646539d</guid>
            <category><![CDATA[gophercon]]></category>
            <category><![CDATA[rob-pike]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Thu, 11 Jan 2024 22:54:49 GMT</pubDate>
            <atom:updated>2024-01-11T22:54:49.338Z</atom:updated>
            <content:encoded><![CDATA[<p>I felt very excited listening to one of the three golang’s initial creators Rob Pike to give a talk about what is good and bad of go in the GopherConAu at the end of 2023. The talk was long but worth listening to. I think it is good timing to start 2024 with a review of this interesting talk.</p><p>I have summarised the main points that I felt aligned to my own understanding of the language. So, the summaries might be subjective to my own perspective but nonetheless provides some insights to the main points of this talk for those who do not have time to listen to the 40mins talk.</p><p>What I felt most important when I am learning golang and using it everyday is that the <strong>mindset </strong>of why the language is the way it is with different approaches to the system, and also the <strong>amazing examples of good practice </strong>the standard library and open source projects provide. I believe that golang has reached a pretty mature stage that it is adopted well by the community with very good amount of examples, books and videos demonstrating and discussing how to best use it.</p><h4>The intention of creating golang is for the designs of systems, and the same purpose still matters today</h4><blockquote>And those factors were what we wanted to address: The complexities of building modern server software: controlling dependencies, programming with large teams with changing personnel, ease of maintainability, efficient testing, effective use of multicore CPUs and networking, and so on.</blockquote><blockquote>In short, Go is not just a programming language. Of course it is a programming language, that’s its definition, but its purpose was to help provide a better way to develop high-quality software, at least compared to our environment 14 plus years ago.</blockquote><blockquote>And that’s still what it’s about today. Go is a project to make building production software easier and more productive.</blockquote><p>The beginning of this chat, Rob Pike talks about why the language was created. The understanding of the history of a language, the intention of its creation is important for us to understand how it is developed and what scenarios are best to use this language.</p><p>Like Rob Piker said, go is a systems’ programming language, and its intention to make system organize more effective, and compile faster, and this still matters today.</p><h3>1. What we done right</h3><h4>1.1 Concurrency</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BQqJNBoJtbPRfOIel569ZQ.png" /><figcaption>Goroutines are lightweight threads of execution, and channels are a communication mechanism that allows goroutines to synchronize and safely exchange data.</figcaption></figure><blockquote>concurrency is fun and we were delighted to have it, but the use cases we had in mind were mostly server stuff, meant to be done in key libraries such as net/http, and not everywhere in every program.</blockquote><p>Golang adopts concurrency using threads to organize code in the way that the go scheduler can manages the execution of goroutines on available operating system threads to achieve efficiency. This is great compared to existing languages such as Java or Phython, whose design did not take consideration of the multi-core of the cpus we use nowadays. This adoption opens doors to further increase efficiency.</p><p>Despite the use cases for concurrency and the understanding of concurrency different from parallelism, the good point still stands: Go helped popularize concurrency as a way to structure server software through code, and not hardware.</p><h4>1.2 interfaces: an approach based on composition rather than inheritance</h4><blockquote>I feel that interfaces are one of the best-designed things in Go.</blockquote><blockquote>Other than a few early conversations about whether data should be included in their definition, they arrived fully formed on literally the first day of discussions.</blockquote><blockquote>The way interfaces work became not only a distinguishing feature of Go, they became the way we thought about libraries, and generality, and composition. It was heady stuff.</blockquote><p>The way golang approaches object oriented design and polymorphism is rather unique and different compared to Java or Python, its implicity focusing on the rather loose categorization using interfaces gives a huge power to connect different small components together.</p><p>It takes quite some time for me to understand its emphasis on the composition rather than inheritance, and the best practices of creating interfaces are to make them very small.</p><p>The statistics show that most of the interfaces are composed of generally 1 to 3 methods. The more methods an interface has, the less abstraction of the object, therefore less flexibility.</p><h4>1.3 standard library: a strong standard library that implements most of the basics needed for server code</h4><blockquote>Although it grew somewhat as an accident, as there was no other place to install Go code at the beginning, the existence of a solid, well-made library with most of what one needed to write 21st century server code was a major asset. It kept the community all working with the same toolkit until we had experience enough to understand what else should be made available. This worked out really well and helped prevent variant libraries from arising, helping unify the community.</blockquote><h3>2. What needs improvement</h3><h4>2.1 package management</h4><blockquote>Second, the business of engaging the community to help solve the dependency management problem was well-intentioned, but when the final design came out, even with plenty of documentation and writing about the theory, many in the community felt slighted.</blockquote><blockquote>This failing was a lesson to the team in how engagement with the community should really work, and much has improved since as a result.</blockquote><h4>2.2. Concurrency is not parallelism, it is only a better way of organizing code and executing via the go scheduler in certain use cases designing web server</h4><blockquote>The related second point is that we took too long to clarify the difference between parallelism — supporting multiple computations in parallel on a multicore machine — and concurrency, which is a way to structure code to do that well.</blockquote><h4>2.3 golang is transitioning from “sets of methods” to “sets of types” in years to come</h4><blockquote>The final answer, as you know, was to design a generalization of interfaces that could absorb more forms of polymorphism, transitioning from “sets of methods” to “sets of types”. It’s a subtle but profound move, one that most of the community seems to be fine with, although I suspect the grumbling will never stop.</blockquote><p>— — —</p><p>Links for the talk script and video below:</p><p><a href="https://commandcenter.blogspot.com/2024/01/what-we-got-right-what-we-got-wrong.html">What We Got Right, What We Got Wrong</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FyE5Tpp2BSGw%3Fstart%3D1904%26feature%3Doembed%26start%3D1904&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyE5Tpp2BSGw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FyE5Tpp2BSGw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d046b2d22094b0fed55025e5b7d86cd4/href">https://medium.com/media/d046b2d22094b0fed55025e5b7d86cd4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5a30646539d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My journey as a software engineer moving to Toronto for over a year, part 2]]></title>
            <link>https://medium.com/@yanglyu5201/my-journey-as-a-software-engineer-moving-to-toronto-for-over-a-year-part-2-2e45735a33da?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e45735a33da</guid>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Fri, 08 Dec 2023 02:55:22 GMT</pubDate>
            <atom:updated>2023-12-08T03:00:28.586Z</atom:updated>
            <content:encoded><![CDATA[<p>In the first part of the journey summary, I have written a long article to describe the emotional journey <a href="https://medium.com/@yanglyu5201/my-journey-as-a-software-engineer-moving-to-toronto-for-over-a-year-9497fa46b7d9">here</a>. An old saying goes like this, the heart is like a painter, and the heart can paint everything in life. Looking back at what I have learned in my past 1 year and 3 months working as a BE golang engineer, I have also gained a lot technically and also more internal confidence as an engineer. Here is a summary.</p><ol><li>I have learned about the design pattern of domain-driven design with Golang. One of the important parts of the BE developer journey is learning design patterns and principles. The SOLID principle helps with understanding the best practices and decisions to be based on. Having the work experience of developing web API with DDD is something I felt very proud of.</li><li>My favorite part of learning how a program works through different microservices is through debugging. Whenever there is a bug, I get excited, because when the code base becomes such a big novel, having a bug is like an exciting thread that could direct me to be a detective and learn through the stories of the bug. There is always so much to learn in the detecting journey.</li><li>Golang is more about conventions than configurations. Understanding the basics of golang by going through the go tour, golang books, and the basics again and again. Reading blogs and following tutorials, it feels like a never-ending journey, yet each time I feel that I have learned something else about the language.</li><li>Unit tests should cover a good percentage of the functions. Writing smaller functions and more unit tests will make debugging much easier. Learning how to mock other services with 3rd party packages and the nuances of using them is quite important. Understand integration tests and how to quickly write tests that achieve the purpose we want.</li><li>The basics matter, slow down to do the learning properly, enjoy the process, and not care about the results sometimes. I love how I learned from a monk in the Buddhist temple that you can either enjoy the process or get the result you want. You can do only one at a time and do not ask to enjoy the process yet control the result at the same time. It is impossible to do, therefore make your decision on what your career means to you as a software developer.</li><li>What I have enjoyed the most is still designing solutions from the basics, learning a lot of knowledge is fun whatsoever. What makes me feel the most achieved is still owning a feature designing a solution and seeing the fruition from start to finish. I know that this opportunity is rare yet knowing that every day I am practicing to be able to design and make my code works helps to motivate me.</li><li>Accept imperfection and mistakes along the way. Yes, I have and will make lots of mistakes. Looking back at the code I wrote and the decisions I have made, which I felt proud of at that time, makes me feel embarrassed. However, that is part of the journey. Having the courage to drop all that frustration and disappointment and switch to self-validation is one of the most important parts of the lessons I have learned. I could choose to be a perfect programmer and beat myself up and hit my head against the impossibility of being perfect in the IT field, or I can accept the trends and streams of changes and as long as I finish the task, I give myself a big praise.</li></ol><p>There are a lot more that I have learned in my past journey, and I feel grateful that I am working as a software engineer and having the opportunity to live and work in another country.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e45735a33da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My journey as a software engineer moving to Toronto for over a year, part 1]]></title>
            <link>https://medium.com/@yanglyu5201/my-journey-as-a-software-engineer-moving-to-toronto-for-over-a-year-9497fa46b7d9?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/9497fa46b7d9</guid>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Thu, 07 Dec 2023 16:51:48 GMT</pubDate>
            <atom:updated>2023-12-08T03:20:41.290Z</atom:updated>
            <content:encoded><![CDATA[<p>Before I headed to Toronto, Canada, I lived in Melbourne, Australia for around 10 years. I loved my life in Australia and I felt comfortable and supported and lived a vibrant, fun life being pretty active with multiple communities locally such as yoga, travel, and dancing groups. I would say I felt bored sometimes with this contentful life I had and wondered what else could be out there outside this box. Despite the general trajectory path I foresee to settle down with a house and partner at some stage in my life, I always wonder if there is something else. Why not try something else even if that means challenges beyond my comfort zone? Regardless, I migrated to Australia without knowing much ahead in my 20s and have achieved a life I felt satisfactory to a good degree, how could it be more difficult moving to Canada?</p><p>Now, when I look back, I feel that I knew nothing about life, and I was overconfident about what could happen in the future by basing predictions on what happened in the past. I felt a lot of fear and anxiety before my trip to Toronto, and in my head, I also had many plans. Almost none of the plans came to fruition. What is the meaning of working in another country when I have had a comfortable fulfilling life in Australia? What is the meaning of any human behavior? I pondered upon these questions quite often, especially when the path did not unfold as planned. I am still glad that this journey drives me out of my comfort zone way further. What matters more in the journey is perhaps the journey itself than any final result I have achieved. Nonetheless, it allows me to reflect and think about many big topics and face myself once and over again without running away.</p><p>Honestly, my answer to the meaning of this journey changes all the time. I feel mostly content that I have given this calling a go and will never regret it when I grow older. I will never have to talk with friends or children with a start like “I wonder if I could shake off my fear and get to the flight to Canada, I wonder what I will do and who I will be…”.</p><p>We all search for meaning and purpose as human beings, we probably search more about the meaning and purpose of our life than happiness and success. Because with a clear purpose and why, we most likely have all the strength to endure any amount of pain. But think about it a second time, a meaning before we do something isn’t more of a motivation/illusion than an innate meaning of that behavior. I know people say their purpose of a career will help others in some aspects, yet we do not know for sure if it indeed helps others if we could put it to the test of space and time. Very honestly, we do not have control over the influence one behavior has on others at all. What I could do as a human being is perhaps only to answer true callings from my heart, do it, and then my brain might generate a meaning to it when we look back, and that will inevitably change with time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5B6SR2UsJkwf7lFbOxxbwA.png" /></figure><p>Looking back, in the past year and 3 months, I have lived through the first long dark, cold, and dry winter and experienced a chilling spring, a greenish-happy summer, a golden autumn, and some early snows of winter. I loved the summer in Toronto, every morning was filled with so much sunshine and green and hope. I would usually go outside in the morning and work in a park nearby. I have also found people in the summer are much more socializing and I was able to make quite some friends here. I loved how direct and close people can get in Toronto, and making friends is much easier than I thought. I joined a Tai Chi group and exercised every Sunday from 10 am to 12 pm. The community of the Tai Chi group is amazing with lots of people to connect with and chat about some deeper topics of life. Summer gave me a lot of amazing memories of the city of Toronto.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*K1l0goMTQBSYaM7RUx-zww.jpeg" /></figure><p>In big contrast, the first winter I had was very challenging. How did I get through the winter with a breakup with my previous boyfriend and no friends in Toronto? I would not want to experience that again despite knowing that I have much more strength than I know I had. It is those long long hours of meditation in the temple, something I could not imagine or expect myself to do in Australia. I had never been challenged emotionally so much in my life. I have never felt such a need to forgive, let go and quiet down. That amount of stress added to my wisdom as well as my wrinkles and my health issues. Winter indeed passes in the end, with a good 6 months of wait. I indeed learned a lot and worked a lot in those dark winter days with an amazing amount of reading, writing, and reflection. When spring comes, everything feels so much different, and Toronto is like a new person with each season of different clothes and personalities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1pAWBfvlk_rxr_2WNjSMCQ.png" /></figure><p>In summary, I think the journey and experience of living in a different country are very individualized and the meaning we could give to a journey is up to us. No big deal whatever happens and no need to even measure the gains and losses. My journey as an engineer or more as a human being still goes on, and I am no longer the same person as I was before this journey, perhaps more fun I hope. Perhaps, that is the meaning of this journey as I am writing it now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9497fa46b7d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang development documentation ru]]></title>
            <link>https://medium.com/@yanglyu5201/golang-development-documentation-ru-eb29cbb1083?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb29cbb1083</guid>
            <category><![CDATA[golang-documentation]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Sun, 14 May 2023 04:56:40 GMT</pubDate>
            <atom:updated>2023-05-14T04:57:03.256Z</atom:updated>
            <content:encoded><![CDATA[<h3>Golang web development documentation rules</h3><p>After developing Golang web app for a year and a half, I have started to realize the importance of Golang documentation and here are some rules to suggest</p><h4>1. every exported element must be documented.</h4><ul><li>Whether it is a structure, an interface, a function, or something else, if it’s exported, it must be documented.</li><li>The convention is to add comments, starting with the name of the exported element.</li><li>As a convention, each comment should be a complete sentence that ends with punctuation.</li><li>when we document a function (or a method), we should highlight what the function intends to do, not how it does it; this belongs to the core of a function and comments, not documentation.</li><li>Furthermore, the documentation should ideally provide enough information that the consumer does not have to look at our code to understand how to use an exported element.</li></ul><pre>// Customer is a customer representation.<br>type Customer struct{}<br> <br>// ID returns the customer identifier.<br>func (c Customer) ID() string { return &quot;&quot; }</pre><h4>2. Deprecated elements</h4><p>It’s possible to deprecate an exported element using the // Deprecated: comment this way:</p><pre>// ComputePath returns the fastest path between two points.<br>// Deprecated: This function uses a deprecated way to compute<br>// the fastest path. Use ComputeFastestPath instead.<br>func ComputePath() {}</pre><p>Then, if a developer uses the ComputePath function, they should get a warning. (Most IDEs handle deprecated comments.)</p><h4>3. Document Packages</h4><p>To help clients and maintainers understand a package’s scope, we should also document each package. The convention is to start the comment with // Package followed by the package name:</p><pre>// Copyright 2009 The Go Authors. All rights reserved.<br>// Use of this source code is governed by a BSD-style<br>// license that can be found in the LICENSE file.<br>// Package math provides basic constants and mathematical functions.<br>//                                                                        ❶<br>// This package does not guarantee bit-identical results<br>// across architectures.<br>package math</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb29cbb1083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang Web Development: understanding Handler Interface]]></title>
            <link>https://medium.com/@yanglyu5201/golang-web-development-understanding-handler-interface-7b0d50c98ef8?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b0d50c98ef8</guid>
            <category><![CDATA[golang-development]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 17:57:30 GMT</pubDate>
            <atom:updated>2023-03-06T17:57:30.440Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding the handler interface is vital to learning web development with golang.</p><h3>1. HTTP Handler</h3><p>A Handler responds to an HTTP request. Its signature function ServeHTTP should write reply headers and data to the ResponseWriter and then return. It is important to remember that it has the ServeHTTP with parameters of the response writer and pointer to an HTTP request.</p><pre>type Handler interface {<br> ServeHTTP(ResponseWriter, *Request)<br>}</pre><p>Any object that has this signature function <strong>ServeHTTP(w http.ResponseWriter, r *http.Request)</strong> can be used as a handler to handle HTTP requests. For example:</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;net/http&quot;<br>)<br><br>type yangHandler struct {<br> url           string<br> authorization string<br>}<br><br>func (h yangHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {<br> fmt.Fprintln(w, &quot;just an example of a demo service&quot;)<br>}<br><br>func main() {<br> var yangH yangHandler<br> http.ListenAndServe(&quot;:8080&quot;, yangH)<br>}</pre><h4>*HandlerFunc</h4><p>The type Handler is different from the type HandlerFunc. The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.</p><pre><br>type HandlerFunc func(ResponseWriter, *Request)<br><br>func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request)</pre><h3><strong>2. HTTP Request Interface</strong></h3><p>A Request represents an HTTP request received by a server or to be sent by a client. An HTTP request mainly contains a Method, URL, Header, Body, and other information.</p><pre>//an HTTP request received by a server or to be sent from client<br>type Request struct {<br> // Method specifies the HTTP method (GET, POST, PUT, etc.).<br> // For client requests, an empty string means GET.<br> Method string<br><br> URL *url.URL<br><br> // Header contains the request header fields either received<br> // by the server or to be sent by the client.<br> //<br> // If a server received a request with header lines,<br> //<br> // Host: example.com<br> // accept-encoding: gzip, deflate<br> // Accept-Language: en-us<br> // fOO: Bar<br> // foo: two<br> //<br> // then<br> //<br> // Header = map[string][]string{<br> //  &quot;Accept-Encoding&quot;: {&quot;gzip, deflate&quot;},<br> //  &quot;Accept-Language&quot;: {&quot;en-us&quot;},<br> //  &quot;Foo&quot;: {&quot;Bar&quot;, &quot;two&quot;},<br> // }<br> //<br> // For incoming requests, the Host header is promoted to the<br> // Request.Host field and removed from the Header map.<br> //<br> // HTTP defines that header names are case-insensitive. The<br> // request parser implements this by using CanonicalHeaderKey,<br> // making the first character and any characters following a<br> // hyphen uppercase and the rest lowercase.<br> //<br> // For client requests, certain headers such as Content-Length<br> // and Connection are automatically written when needed and<br> // values in Header may be ignored. See the documentation<br> // for the Request.Write method.<br> Header Header<br><br> // Body is the request&#39;s body.<br> //<br> // For client requests, a nil body means the request has no<br> // body, such as a GET request. The HTTP Client&#39;s Transport<br> // is responsible for calling the Close method.<br> //<br> // For server requests, the Request Body is always non-nil<br> // but will return EOF immediately when no body is present.<br> // The Server will close the request body. The ServeHTTP<br> // Handler does not need to.<br> //<br> // Body must allow Read to be called concurrently with Close.<br> // In particular, calling Close should unblock a Read waiting<br> // for input.<br> Body io.ReadCloser<br><br><br> // Close indicates whether to close the connection after<br> // replying to this request (for servers) or after sending this<br> // request and reading its response (for clients).<br> //<br> // For server requests, the HTTP server handles this automatically<br> // and this field is not needed by Handlers.<br> //<br> // For client requests, setting this field prevents re-use of<br> // TCP connections between requests to the same hosts, as if<br> // Transport.DisableKeepAlives were set.<br> Close bool<br><br>  // Form contains the parsed form data, including both the URL<br> // field&#39;s query parameters and the PATCH, POST, or PUT form data.<br> // This field is only available after ParseForm is called.<br> // The HTTP client ignores Form and uses Body instead.<br> Form url.Values<br><br> // PostForm contains the parsed form data from PATCH, POST<br> // or PUT body parameters.<br> //<br> // This field is only available after ParseForm is called.<br> // The HTTP client ignores PostForm and uses Body instead.<br> PostForm url.Values<br><br>...<br>}</pre><p>To create a new request, we use http.NewRequest, and pass in the method, URL, and body.</p><pre>//signature function<br>func NewRequest(method, url string, body io.Reader) (*Request, error)<br><br>//example to create a new http request<br>req, err := http.NewRequest(method, url, body)<br> if err != nil {<br>  return err<br> }</pre><h4>* Header</h4><p>Note that the Header interface is as below, and represents the key-value pairs in an HTTP header. The keys should be in <strong>canonical form</strong>, as returned by CanonicalHeaderKey. The canonical form means the first character and any characters following a hyphen uppercase and the rest lowercase. Example: “X-Username”.</p><p>A header contains a few methods that is used often such as a header.Set method which replaces any existing value, while the header. Add method appends to any existing values associated with the key. <strong>The key is case insensitive</strong>; it is canonicalized by textproto.CanonicalMIMEHeaderKey. To use non-canonical keys, assign to the map directly.</p><pre>type Header map[string][]string<br><br>// Set sets the header entries associated with key to the<br>// single element value. It replaces any existing values<br>// associated with key. The key is case insensitive; it is<br>// canonicalized by textproto.CanonicalMIMEHeaderKey.<br>// To use non-canonical keys, assign to the map directly.<br>func (h Header) Set(key, value string)<br><br>// an example to set headers for a http request<br>req.Header.Set(&quot;Content-Type&quot;, &quot;application/json&quot;)</pre><h4>* url in http request</h4><p>Firstly, it is important to understand the url.URL type</p><pre>type URL struct {<br> Scheme      string<br> Opaque      string    // encoded opaque data<br> User        *Userinfo // username and password information<br> Host        string    // host or host:port<br> Path        string    // path (relative paths may omit leading slash)<br> RawPath     string    // encoded path hint (see EscapedPath method)<br> OmitHost    bool      // do not emit empty host (authority)<br> ForceQuery  bool      // append a query (&#39;?&#39;) even if RawQuery is empty<br> RawQuery    string    // encoded query values, without &#39;?&#39;<br> Fragment    string    // fragment for references, without &#39;#&#39;<br> RawFragment string    // encoded fragment hint (see EscapedFragment method)<br>}</pre><p>The url package has a few functions that is useful when creating a new request. PathEscape escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.</p><pre><br>//some userID might have special characters and need to be converted<br>//to string that can be safely placed inside a url path<br>func PathEscape(s string) string</pre><p>For example:</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;net/url&quot;<br>)<br><br>func main() {<br> path := url.PathEscape(&quot;auth0|123456789&quot;)<br> fmt.Println(path)<br><br>}<br><br>//it returns auth0%7C123456789</pre><h3>3. HTTP ResponseWriter interface</h3><p>HTTP responseWriter interface has 3 main functions, and inherit writer interface, and also allow write to its header.</p><pre>type ResponseWriter interface {<br> // Header returns the header map that will be sent by<br> // WriteHeader. The Header map also is the mechanism with which<br> // Handlers can set HTTP trailers.<br> //<br> // Changing the header map after a call to WriteHeader (or<br> // Write) has no effect unless the HTTP status code was of the<br> // 1xx class or the modified headers are trailers.<br> //<br> // There are two ways to set Trailers. The preferred way is to<br> // predeclare in the headers which trailers you will later<br> // send by setting the &quot;Trailer&quot; header to the names of the<br> // trailer keys which will come later. In this case, those<br> // keys of the Header map are treated as if they were<br> // trailers. See the example. The second way, for trailer<br> // keys not known to the Handler until after the first Write,<br> // is to prefix the Header map keys with the TrailerPrefix<br> // constant value. See TrailerPrefix.<br> //<br> // To suppress automatic response headers (such as &quot;Date&quot;), set<br> // their value to nil.<br> Header() Header<br><br> // Write writes the data to the connection as part of an HTTP reply.<br> //<br> // If WriteHeader has not yet been called, Write calls<br> // WriteHeader(http.StatusOK) before writing the data. If the Header<br> // does not contain a Content-Type line, Write adds a Content-Type set<br> // to the result of passing the initial 512 bytes of written data to<br> // DetectContentType. Additionally, if the total size of all written<br> // data is under a few KB and there are no Flush calls, the<br> // Content-Length header is added automatically.<br> //<br> // Depending on the HTTP protocol version and the client, calling<br> // Write or WriteHeader may prevent future reads on the<br> // Request.Body. For HTTP/1.x requests, handlers should read any<br> // needed request body data before writing the response. Once the<br> // headers have been flushed (due to either an explicit Flusher.Flush<br> // call or writing enough data to trigger a flush), the request body<br> // may be unavailable. For HTTP/2 requests, the Go HTTP server permits<br> // handlers to continue to read the request body while concurrently<br> // writing the response. However, such behavior may not be supported<br> // by all HTTP/2 clients. Handlers should read before writing if<br> // possible to maximize compatibility.<br> Write([]byte) (int, error)<br><br> // WriteHeader sends an HTTP response header with the provided<br> // status code.<br> //<br> // If WriteHeader is not called explicitly, the first call to Write<br> // will trigger an implicit WriteHeader(http.StatusOK).<br> // Thus explicit calls to WriteHeader are mainly used to<br> // send error codes or 1xx informational responses.<br> //<br> // The provided code must be a valid HTTP 1xx-5xx status code.<br> // Any number of 1xx headers may be written, followed by at most<br> // one 2xx-5xx header. 1xx headers are sent immediately, but 2xx-5xx<br> // headers may be buffered. Use the Flusher interface to send<br> // buffered data. The header map is cleared when 2xx-5xx headers are<br> // sent, but not with 1xx headers.<br> //<br> // The server will automatically send a 100 (Continue) header<br> // on the first read from the request body if the request has<br> // an &quot;Expect: 100-continue&quot; header.<br> WriteHeader(statusCode int)<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b0d50c98ef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang Web Development: Printout HTTP request and response]]></title>
            <link>https://medium.com/@yanglyu5201/golang-web-development-printout-http-request-and-response-3a939ab7140e?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a939ab7140e</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[go-web-development]]></category>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Sat, 04 Mar 2023 17:01:12 GMT</pubDate>
            <atom:updated>2023-03-04T17:01:12.799Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many times when we need to print out the HTTP request and response for debugging purposes, and below provides the script for printing out the request and response</p><h3>1. printout the request</h3><pre>//create an http request<br>request, err := http.NewRequest(method, url, body)<br> if err != nil {<br>  return nil, err<br> }<br><br> request.Header.Set(&quot;Content-Type&quot;, &quot;application/json&quot;)<br>... //set more headers if needed<br> <br>//printout the request for debugging purpose<br> requestDump, err := httputil.DumpRequestOut(request, true)<br> if err != nil {<br>  return nil, err<br> }<br><br> fmt.Printf(&quot;Debug: REQUEST is: %s\n&quot;, string(requestDump))</pre><h3>2. printout the response</h3><pre>//receive the response<br>response, err := http.Client.Do(req)<br> if err != nil {<br>  return nil, err<br> }<br><br> //printout the response for debugging purpose<br> defer resp.Body.Close()<br><br> responseDump, err := httputil.DumpResponse(response, true)<br> if err != nil {<br>  return nil, err<br> }<br> fmt.Printf(&quot;Response is: %s\n&quot;, string(responseDump))</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a939ab7140e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Commit Message Conventions For Web development]]></title>
            <link>https://medium.com/@yanglyu5201/git-commit-message-conventions-for-web-development-ffa8134288cc?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffa8134288cc</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 06:34:17 GMT</pubDate>
            <atom:updated>2023-02-24T08:18:49.479Z</atom:updated>
            <content:encoded><![CDATA[<p>This year, I have been working on improving some of my work flow as a backend engineer and have reflected on some of the common practices that might help in general with web development.</p><p>This article provides an idea for the git commit message conventions for web development. It aims to help engineers work in a team to understand the commit history easily with each commit message categorized into types. It could also be used to trigger pipeline builds when certain types of commits are selected.</p><h3>1. Commit Message Style</h3><p>This style is mainly following AngularJS Git Commit Message Conventions with some minor changes and summaries.</p><pre>&lt;type&gt;[optional scope]: &lt;description&gt;<br>// empty line<br>[optional body]<br>// empty line<br>[optional footer(s)]</pre><p>Example of using angularJS commit style is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gn-cIjIzoWiE4V-bFmcbCg.png" /></figure><h3><strong>2. Message Header</strong></h3><pre>&lt;type&gt;[optional scope]: &lt;description&gt;</pre><p>The most important part of the commit message header is the type because the categorization will allow other engineers to have a clear understanding of the main purpose of the commit.</p><h4>2.1 Type</h4><p>My summary and small changes to the original types is as follows:</p><h4><strong>2.1.1 Types of functional code:</strong></h4><ul><li><strong>feat (feature)</strong></li><li><strong>perf (make the existing feature better)</strong></li><li><strong>refactor(change main structure of code)</strong></li><li><strong>fix (bug fix)</strong></li><li><strong>style (formatting, typo…)</strong></li></ul><h4>2.1.2 Types of nonfunctional code:</h4><ul><li><strong>test (changes to unit test)</strong></li><li><strong>docs (document)</strong></li><li><strong>chore (other changes nonfunction related, such as a bump, or vendor)</strong></li><li><strong>ci</strong></li></ul><h4>2.2 Scope</h4><p>the scope is optional and more project-based.</p><h4>2.3 Subject — Message</h4><p>A short description of the change</p><ul><li>Need to start with a verb</li><li>Need to be lowercase</li><li>use imperative, present tense: “change” not “changed” nor “changes”</li></ul><h3>3. The Body</h3><p>The body is <strong>optional</strong> lines that introduce the motivation behind the change or just describe slightly more detailed information.</p><h3>4. The Footer</h3><p>Put the result of this commit, for example</p><pre>Fix Issue#xxx<br><br>Close Issue#xxx<br><br>Fix Bug #xxxx</pre><p>Finally, use “git log — oneline — grep “^feat|^fix|^perf” to easily see the latest feature or fix or perf changes.</p><blockquote>Reference:</blockquote><ol><li><a href="https://nitayneeman.com/posts/understanding-semantic-commit-messages-using-git-and-angular/">https://nitayneeman.com/posts/understanding-semantic-commit-messages-using-git-and-angular/</a></li><li><a href="https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#">https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#</a></li><li><a href="https://www.conventionalcommits.org/en/v1.0.0-beta.4/#summary">https://www.conventionalcommits.org/en/v1.0.0-beta.4/#summary</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffa8134288cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Initial Setup for Terminals(Iterm2) on a new MacBook]]></title>
            <link>https://medium.com/@yanglyu5201/how-to-set-up-iterm2-and-other-terminal-things-on-a-new-macbook-24b8c4e6315d?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/24b8c4e6315d</guid>
            <category><![CDATA[new-laptop-setup]]></category>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[zsh]]></category>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Tue, 11 Oct 2022 20:15:58 GMT</pubDate>
            <atom:updated>2022-10-20T01:33:08.369Z</atom:updated>
            <content:encoded><![CDATA[<p>Prerequisites:</p><ul><li>Install the homebrew with Xcode command line tools</li></ul><p><a href="https://brew.sh/">https://brew.sh/</a></p><ul><li>Install gh for github page raising PR, brew install gh</li></ul><p>— -</p><p><strong>Step 1: Install Iterm2</strong></p><p><a href="https://iterm2.com/">https://iterm2.com/</a></p><p><strong>Step 2. Install Oh My Zsh</strong></p><p><a href="https://ohmyz.sh/#install">https://ohmyz.sh/#install</a></p><p><strong>Step 3. Pick a color theme for iterm2</strong></p><p><a href="https://iterm2colorschemes.com/">https://iterm2colorschemes.com/</a></p><p><strong>Step 4. Add zsh autosuggestion</strong></p><p><a href="https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md">https://github.com/zsh-users/zsh-autosuggestions</a></p><p>Step 5. Optional — Powerline shell setup</p><p><a href="https://github.com/b-ryan/powerline-shell">GitHub - b-ryan/powerline-shell: A beautiful and useful prompt for your shell</a></p><p>Note: make sure you install the fonts and select in the preference →settings → text in iterm2. Otherwise, the symbol might not show properly.</p><p>Step 6. Optional — set up tmux to manage multiple windows and sessions in iterm</p><p><strong>Step 7. Install Git and Add SSH key to github account</strong></p><ul><li><a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent">Generating a new SSH key and adding it to the ssh-agent - GitHub Docs</a></li><li><a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account">Adding a new SSH key to your GitHub account - GitHub Docs</a></li></ul><p><strong>Step 8. Allow the terminal to open up VS code</strong></p><p><a href="https://www.freecodecamp.org/news/how-to-open-visual-studio-code-from-your-terminal/#:~:text=Once%20your%20terminal%20is%20open,Then%20hit%20enter%20.&amp;text=Once%20you%20hit%20enter%20%2C%20VS%20Code%20will%20now%20open">https://www.freecodecamp.org/news/how-to-open-visual-studio-code-from-your-terminal/#:~:text=Once%20your%20terminal%20is%20open,Then%20hit%20enter%20.&amp;text=Once%20you%20hit%20enter%20%2C%20VS%20Code%20will%20now%20open</a>.</p><p>Note: change VS code terminal font size</p><p><a href="https://www.kindacode.com/article/vs-code-ways-to-change-terminal-font-size/">https://www.kindacode.com/article/vs-code-ways-to-change-terminal-font-size/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24b8c4e6315d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A good summary of Go lang basic syntax]]></title>
            <link>https://medium.com/@yanglyu5201/a-good-summary-of-go-lang-basic-syntax-33a5b642d52?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/33a5b642d52</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 01:06:27 GMT</pubDate>
            <atom:updated>2022-01-03T01:06:27.024Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Go lang command line</h3><pre>1. go fmt<br>2. go vet<br>3. go build: can specify the GOOS,GOARCH for operating system<br>4. go run<br>---<br>5. go get: add dependencies to current module and install them<br>6. go mod: dependency management<br>7. go install<br>---<br>8. go test:</pre><h3>2. Go lang Control flows</h3><p>Conditionals:</p><pre>if condition1 {<br>} else if condition2 {<br>} else {<br>}</pre><pre>---<br>switch i {<br>  case 0:<br>  case 1:<br>    fallthrough<br>  case 3:<br>    f()<br>  default:<br>    ...<br>}</pre><p>loops:</p><pre>//for loop<br>for i:=0; i&lt;n; i++ {<br>  something<br>}</pre><pre>---</pre><pre>//for range </pre><pre>for i,v := range array1 {<br>}</pre><pre>for key,value := range map1 { <br>}</pre><h3>3. Go lang Data Structure</h3><p>When using new to make a slice/array/map/instance, it returns the pointer of the first element. When using make, it returns the first element.</p><pre>//const vs var<br>const x<br>var x<br>var x,y int = 1,2<br>x,y,z := true, 123, &quot;steve&quot;</pre><pre>//array is a fixed number of continuous memory space</pre><pre>//slice is a resizable array<br>slice1 := []int{}<br>slice2 := append(slice1, 1) </pre><pre>//make or new slice or array<br>slice1 := new([]int)<br>slice2 := make([]int, 10, 20)<br>slice3 := make([]int, 0)<br>slice4 := make([]int,10)</pre><pre>//map is key value pair<br>myMap :=make(map[string]string, 10). //define the length of the map<br>myMap :=make(map[string]string) //do not have to define the size<br>myMap[&quot;a&quot;]=&quot;b&quot; //assign value to its key</pre><pre>//notice that the element of the map could be a function, as follows<br>myFuncMap :=maps[string]func() int{<br>  &quot;funcA&quot;: func() int{return 1},<br>}</pre><pre>//struct<br>h1 :=new(Human)</pre><h3>4. Go lang Function</h3><pre>main()</pre><pre>//function that reads the fields from the receiver</pre><pre>func (s receiver_type) methodName(params) {<br>xxx<br>}</pre><pre>//reflect function to find the type and value of a variable<br>t := reflect.TypeOf(mymap)<br>v := reflect.ValueOf(mymap)</pre><h3>5. Struct vs Type</h3><p>Type Struct is a combination of fields. Type Interface is a combination of methods. You can add different struct types to the same interface instance.</p><p>public and private functions, public functions can be seen from a different package. Private functions can not be seen from a different package.</p><pre>//a combination of functions<br>type IF interface{<br>  getName() string<br>}</pre><pre>//define a new data struct<br>type Human struct{<br>  firstName string<br>  lastName string<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33a5b642d52" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes: drain node vs cordon node]]></title>
            <link>https://medium.com/@yanglyu5201/kubernetes-drain-node-vs-cordon-node-8b979eb7bbbe?source=rss-1f727e3428da------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b979eb7bbbe</guid>
            <dc:creator><![CDATA[Yang Lyu]]></dc:creator>
            <pubDate>Sun, 19 Dec 2021 13:23:00 GMT</pubDate>
            <atom:updated>2021-12-19T13:23:00.094Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Drain node</h3><p>This will mark the node as unschedulable and also evict pods on the node.</p><pre>The given node will be marked unschedulable to prevent new pods from arriving. &#39;drain&#39; evicts the pods. Otherwise, it will use normal DELETE to delete the pods. The &#39;drain&#39; evicts or deletes all pods except mirror pods (which cannot be deleted through the API server).  If there are DaemonSet-managed pods, drain will not proceed without --ignore-daemonsets, and regardless it will not delete any DaemonSet-managed pods, because those pods would be immediately replaced by the DaemonSet controller, which ignores unschedulable markings.  If there are any pods that are neither mirror pods nor managed by ReplicationController, ReplicaSet, DaemonSet, StatefulSet or Job, then drain will not delete any pods unless you use --force.  <br>--force will also allow deletion to proceed if the managing resource of one or more pods is missing.</pre><pre>&#39;drain&#39; waits for graceful termination. You should not operate on the machine until the command completes.</pre><pre>When you are ready to put the node back into service, use kubectl uncordon, which will make the node schedulable again.</pre><pre>Examples:<br>  # Drain node &quot;foo&quot;, even if there are pods not managed by a<br>ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet on it.<br>  $ kubectl drain foo --force<br>  <br>  # As above, but abort if there are pods not managed by a<br>ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet, and use a grace period of 15 minutes.<br>  $ kubectl drain foo --grace-period=900</pre><pre>Options:<br>      --delete-emptydir-data=false: Continue even if there are pods using emptyDir(local data that will be deleted when the node is drained).<br>      --ignore-daemonsets</pre><h3>2. cordon node</h3><p>Mark node as unschedulable.</p><pre>Examples:<br> # Mark node “foo” as unschedulable.<br> kubectl cordon foo</pre><h3>3. uncordon node</h3><p>Mark node as schedulable again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b979eb7bbbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>