<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Abhishek Somani</title>
    <description>The latest articles on Forem by Abhishek Somani (@abusomani).</description>
    <link>https://forem.com/abusomani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1034243%2Fc3f623ac-1a82-4524-9c6a-99d83d8d52f3.jpeg</url>
      <title>Forem: Abhishek Somani</title>
      <link>https://forem.com/abusomani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abusomani"/>
    <language>en</language>
    <item>
      <title>Handle json from multiple sources using JsonHandlers</title>
      <dc:creator>Abhishek Somani</dc:creator>
      <pubDate>Thu, 09 Mar 2023 09:38:10 +0000</pubDate>
      <link>https://forem.com/abusomani/handle-json-from-multiple-sources-using-jsonhandlers-1g40</link>
      <guid>https://forem.com/abusomani/handle-json-from-multiple-sources-using-jsonhandlers-1g40</guid>
      <description>&lt;p&gt;Bored of handling json from multiple different sources like Files, Http requests or responses?&lt;/p&gt;

&lt;p&gt;You no longer have to be!  🤩&lt;/p&gt;

&lt;h1&gt;JsonHandlers&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YaDZR3qN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dahkenlmo/image/upload/v1678346700/jsonhandlers_hjca2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YaDZR3qN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dahkenlmo/image/upload/v1678346700/jsonhandlers_hjca2i.png" alt="Json Handlers" width="880" height="942"&gt;&lt;/a&gt;&lt;br&gt;
   &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;A go module where you want to integrate jsonhandlers. To create one, follow this &lt;a href="https://go.dev/doc/tutorial/create-module"&gt;guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go get github.com/abusomani/jsonhandlers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;A very useful feature of Go’s import statement are aliases. A common use case for import aliases is to provide a shorter alternative to a library’s package name.&lt;/p&gt;

&lt;p&gt;In this example, we save ourselves having to type &lt;code&gt;jsonhandlers&lt;/code&gt; everytime we want to call one of the library’s functions, we just use &lt;code&gt;jh&lt;/code&gt; instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import (
    jh "github.com/abusomani/jsonhandlers"
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Options
&lt;/h2&gt;

&lt;p&gt;Jsonhandlers package exposes multiple options while creating a new &lt;code&gt;jsonhandler&lt;/code&gt; to be able to read/write json from sources like Files, Http Requests or Http responses. &lt;/p&gt;

&lt;h3&gt;
  
  
  WithFileHandler
&lt;/h3&gt;

&lt;p&gt;You can use the &lt;code&gt;WithFileHandler&lt;/code&gt; option to read/write Json from/to a file. For this, you need to create a new jsonhandler with the file handler option.&lt;/p&gt;

&lt;p&gt;&lt;a href="//./example/operations/file_handling.go"&gt;Example&lt;/a&gt; to understand &lt;code&gt;WithFileHandler&lt;/code&gt; in more detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package operations

import (
    "fmt"

    "github.com/abusomani/jsonhandlers"
)

func GetStudentsFromFile() []student {
    return handleFile()
}

func handleFile() []student {
    jh := jsonhandlers.New(jsonhandlers.WithFileHandler(testFilePath))

    var sch school
    err := jh.Unmarshal(&amp;amp;sch)
    handleError("error in unmarshalling %s", err)
    fmt.Printf("School info is : %+v\n", sch)

    // add a new student to the school
    sch.Students = append(sch.Students[:2], student{
        Id:     3,
        Name:   "The new student",
        Branch: "AI",
    })

    err = jh.Marshal(sch)
    handleError("error in marshalling %s", err)
    fmt.Printf("Updated school info after admission of new student is : %+v\n", sch)

    // remove the new student as he was very mischievous
    sch.Students = sch.Students[:2]

    err = jh.Marshal(sch)
    handleError("error in marshalling %s", err)
    fmt.Printf("Updated school info after retaining all good students is : %+v\n", sch)
    return sch.Students
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  WithHTTPRequestHandler
&lt;/h3&gt;

&lt;p&gt;You can use the &lt;code&gt;WithHTTPRequestHandler&lt;/code&gt; option to read Json from a Http Request and to write Json to a Http ResponseWriter. For this, you need to create a new jsonhandler with the Http request handler option.&lt;/p&gt;

&lt;p&gt;&lt;a href="//./example/operations/http_request_handling.go"&gt;Example&lt;/a&gt; to understand &lt;code&gt;WithHTTPRequestHandler&lt;/code&gt; in more detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package operations

import (
    "net/http"

    "github.com/abusomani/jsonhandlers"
)

type studentSearchRequest struct {
    Name string
}

type studentSearchResponse struct {
    Info student
}

func HandleHTTPRequest(students []student) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

    jh := jsonhandlers.New(jsonhandlers.WithHTTPRequestHandler(w, r))

        var reqBody studentSearchRequest
        err := jh.Unmarshal(&amp;amp;reqBody)
        if err != nil {
            errPayload := struct {
                StatusCode int
                Message    string
            }{
                StatusCode: http.StatusBadRequest,
                Message:    err.Error(),
            }
            // request is bad
            jh.Marshal(errPayload)
            return
        }

        for _, student := range students {
            // student found
            if student.Name == reqBody.Name {
                // response has the right student info written
                jh.Marshal(studentSearchResponse{
                    Info: student,
                })
                return
            }
        }

        errPayload := struct {
            StatusCode int
            Message    string
        }{
            StatusCode: http.StatusInternalServerError,
            Message:    "something went wrong",
        }
        // student not found
        jh.Marshal(errPayload)
    })
}

/*
  Sample request to be hit on the localhost server to test WithHTTPRequestHandler functionality.
  curl http://localhost:8080/search -d '{"Name": "Abhishek Somani"}'
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  WithHTTPResponseHandler
&lt;/h3&gt;

&lt;p&gt;You can use the &lt;code&gt;WithHTTPResponseHandler&lt;/code&gt; option to read/write Json from/to a Http Response. For this, you need to create a new jsonhandler with the Http response handler option.&lt;/p&gt;

&lt;p&gt;&lt;a href="//./example/operations/http_response_handling.go"&gt;Example&lt;/a&gt; to understand &lt;code&gt;WithHTTPResponseHandler&lt;/code&gt; in more detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package operations

import (
    "fmt"
    "log"
    "net/http"

    "github.com/abusomani/jsonhandlers"
)

type user struct {
    Id        int
    FirstName string
    LastName  string
    Age       int
    Gender    string
    Email     string
}

type getUsersResponse struct {
    Users []user
}

func HandleHTTPResponse() {
    resp, err := http.Get("https://dummyjson.com/users")
    if err != nil {
        log.Fatalf("unable to make the get request %s", err.Error())
    }
    jh := jsonhandlers.New(jsonhandlers.WithHTTPResponseHandler(resp))

    var userResp getUsersResponse
    jh.Unmarshal(&amp;amp;userResp)
    fmt.Printf("response is %+v\n", userResp)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run examples
&lt;/h2&gt;

&lt;p&gt;To run the examples present in the &lt;a href="//./example/"&gt;example&lt;/a&gt; folder you need to first checkout this package by doing a &lt;code&gt;git clone&lt;/code&gt;. Once you have checked out this package, then you can run the &lt;a href="//./example/main.go"&gt;main.go&lt;/a&gt; using the following command to see all the examples in action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go run example/main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope you enjoyed! ❤️&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>go</category>
      <category>programming</category>
      <category>github</category>
    </item>
    <item>
      <title>Style your terminals using Go-Palette 🎨</title>
      <dc:creator>Abhishek Somani</dc:creator>
      <pubDate>Sun, 05 Mar 2023 18:58:37 +0000</pubDate>
      <link>https://forem.com/abusomani/style-your-terminals-using-go-palette-21fm</link>
      <guid>https://forem.com/abusomani/style-your-terminals-using-go-palette-21fm</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038121%2Fgopher_jftcse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038121%2Fgopher_jftcse.png" alt="Go-Palette"&gt;&lt;/a&gt;&lt;br&gt;
   &lt;/p&gt;

&lt;p&gt;Go-Palette provides elegant and convenient style definitions using ANSI colors. &lt;br&gt;
It is fully compatible and wraps the &lt;code&gt;fmt&lt;/code&gt; &lt;a href="https://pkg.go.dev/fmt" rel="noopener noreferrer"&gt;library&lt;/a&gt; for nice terminal layouts. &lt;/p&gt;
&lt;h2&gt;
  
  
  Example written using Go-palette package
&lt;/h2&gt;

 
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038121%2Fgo-palette-example_q5w01k.png" alt="Output of running the example written using Go-palette"&gt;

&lt;h2&gt;
  
  
  Supported Colors &amp;amp; Formats
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Standard colors
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fstandard-colors_kbxyyi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fstandard-colors_kbxyyi.png" alt="standard colors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following colors are supported to be used by their names for both foreground and background as shown in Example using color names&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Color Name&lt;/th&gt;
&lt;th&gt;Color Code&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Black&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Red&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Green&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Yellow&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Blue&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Magenta&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cyan&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;White&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightBlack&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightRed&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightGreen&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightYellow&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightBlue&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightMagenta&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightCyan&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BrightWhite&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Standard colors used as foreground as well as background
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fstandard-colors-fg-bg_vxr67y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fstandard-colors-fg-bg_vxr67y.png" alt="standard colors used as foreground as well as background"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Supported Foreground Palette
&lt;/h3&gt;

&lt;p&gt;The following palette is supported as foreground/text colors. The numbers represent the color-codes which can be used as shown in Example using color codes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038121%2Fforeground-palette_klb2o4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038121%2Fforeground-palette_klb2o4.png" alt="complete supported foreground palette"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Supported Background Palette
&lt;/h3&gt;

&lt;p&gt;The following palette is supported as background colors. The numbers represent the color-codes which can be used as shown in Example using color codes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038122%2Fbackground-palette_neiykd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038122%2Fbackground-palette_neiykd.png" alt="complete supported background palette"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Supported Text Formats
&lt;/h3&gt;

&lt;p&gt;The following text formats are supported.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reset&lt;/li&gt;
&lt;li&gt;Bold&lt;/li&gt;
&lt;li&gt;Dim&lt;/li&gt;
&lt;li&gt;Italic&lt;/li&gt;
&lt;li&gt;Underline&lt;/li&gt;
&lt;li&gt;SlowBlink&lt;/li&gt;
&lt;li&gt;Hidden&lt;/li&gt;
&lt;li&gt;Strikethrough&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fspecial-effects_bwuurg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fspecial-effects_bwuurg.gif" alt="supported text formats"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go get github.com/abusomani/go-palette
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;After installing the &lt;code&gt;go-palette&lt;/code&gt; package, we start using it the following way.&lt;/p&gt;
&lt;h3&gt;
  
  
  Import
&lt;/h3&gt;

&lt;p&gt;A very useful feature of Go’s import statement are aliases. A common use case for import aliases is to provide a shorter alternative to a library’s package name.&lt;/p&gt;

&lt;p&gt;In this example, we save ourselves having to type &lt;code&gt;palette&lt;/code&gt; everytime we want to call one of the library’s functions, we just use &lt;code&gt;pal&lt;/code&gt; instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import (
    pal "github.com/abusomani/go-palette/palette"
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example using Color names
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    pal "github.com/abusomani/go-palette/palette"
)

func main() {
    p := pal.New()
    p.Println("This text is going to be in default color.")
    p.SetOptions(pal.WithBackground(pal.Color(pal.BrightYellow)), pal.WithForeground(pal.Black))
    p.Println("This text is going to be in black color with a yellow background.")
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038119%2Fcode-output_lup9j1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038119%2Fcode-output_lup9j1.png" alt="Code output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example using Color codes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    pal "github.com/abusomani/go-palette/palette"
)

func main() {
    p := pal.New()
    p.Println("This text is going to be in default color.")
    // We can use color codes from the palette to set as foreground and background colors
    p.SetOptions(pal.WithBackground(pal.Color(11)), pal.WithForeground(0))
    p.Println("This text is going to be in black color with a yellow background.")
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038119%2Fcode-output_lup9j1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038119%2Fcode-output_lup9j1.png" alt="Code output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example using Special effects
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    pal "github.com/abusomani/go-palette/palette"
)

func main() {
    p := pal.New(pal.WithSpecialEffects([]pal.Special{pal.Bold}))
    p.Println("Bold")
    p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Dim}))
    p.Println("Dim")
    p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Italic}))
    p.Println("Italic")
    p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Underline}))
    p.Println("Underline")
    p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.SlowBlink}))
    p.Println("SlowBlink")
    p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Hidden}))
    p.Print("Hidden")
    p.SetOptions(pal.WithDefaults())
    p.Println("&amp;lt;-Hidden")
    p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Strikethrough}))
    p.Println("Strikethrough")
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Flush
&lt;/h3&gt;

&lt;p&gt;Flush resets the Palette options with default values and disables the Palette.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    pal "github.com/abusomani/go-palette/palette"
)

func main() {
    p := pal.New()
    p.Println("This text is going to be in default color.")
    // We can use color codes from the palette to set as foreground and background colors
    p.SetOptions(pal.WithBackground(pal.BrightMagenta), pal.WithForeground(pal.Black))
    p.Println("This text is going to be in black color with a bright magenta background.")
    p.Flush()
    p.Println("This text is going to be in default color.")
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fflush-code-output_ejrzoh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdahkenlmo%2Fimage%2Fupload%2Fv1678038120%2Fflush-code-output_ejrzoh.png" alt="Flush output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;p&gt;Go-Palette provides ANSI colors only. Windows does not support ANSI out of the box. To toggle the ANSI color support follow the steps listed in this &lt;a href="https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling" rel="noopener noreferrer"&gt;superuser thread&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Different behaviours in special effects
&lt;/h3&gt;

&lt;p&gt;Go-Palette provides styled support using ANSI Color codes through escape sequences. This varies between different Terminals based on its setting. Refer &lt;a href="https://en.wikipedia.org/wiki/ANSI_escape_code" rel="noopener noreferrer"&gt;ANSI Escape Codes&lt;/a&gt; for more details.&lt;/p&gt;

&lt;h2&gt;
  
  
  More details
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://pkg.go.dev/github.com/abusomani/go-palette@v1.0.0/palette" rel="noopener noreferrer"&gt;Package Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank You ❤️ &lt;/p&gt;

</description>
      <category>opensource</category>
      <category>go</category>
      <category>github</category>
      <category>programming</category>
    </item>
    <item>
      <title>Becoming a star using the STAR technique</title>
      <dc:creator>Abhishek Somani</dc:creator>
      <pubDate>Sat, 04 Mar 2023 13:22:10 +0000</pubDate>
      <link>https://forem.com/abusomani/becoming-a-star-using-the-star-technique-228l</link>
      <guid>https://forem.com/abusomani/becoming-a-star-using-the-star-technique-228l</guid>
      <description>&lt;p&gt;STAR stands for &lt;strong&gt;S&lt;/strong&gt;ituation, &lt;strong&gt;T&lt;/strong&gt;ask, &lt;strong&gt;A&lt;/strong&gt;ction, &lt;strong&gt;R&lt;/strong&gt;esult. A strategy that is significantly helpful in response to Behavioural aka Competency aka Leadership questions, which typically start with phrases such as, "Describe a time when..." and "Tell me an example where....". Let’s understand each of these concepts in a brief manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Situation:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Spend few moments and think of a situation similar to what the interviewer is asking you which had a successful outcome. If there was not a successful outcome, never hesitate to talk about failures. Remember that the interviewer wants you to succeed. They are people who understand that journey is not just successful outcomes but also intermittent failures.&lt;/li&gt;
&lt;li&gt;Candidates usually make a mistake of either jumping on the question immediately without putting enough thoughts which results in either the candidate missing on strong situations that could have been concrete examples to the given question or the interviewer feeling that the candidate does not put enough thoughts before answering.&lt;/li&gt;
&lt;li&gt;Remember to always include the important aspects of who, what, where, when and how so that the interviewer can easily visualise and understand your situation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Task:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Explain the task you were assigned and how you took ownership in that situation. Throw some light on your responsibilities in that situation. Pin point the task that you were directly responsible for. Convey the details to the interviewer and at the same time have a look on the clock.&lt;/li&gt;
&lt;li&gt;Remember to walk your interview through some critical aspects like : What was the task assigned to you for the given situation? Secondly, was it you who identified this task? What was the expected result of this task and did it meet the expectations?&lt;/li&gt;
&lt;li&gt;Keep it specific yet concise. Always look out on the clock. Time is a critical component during such rounds where you don't want to narrate long stories.&lt;/li&gt;
&lt;li&gt;Make sure you highlight the constraints, challenges and obstacles you faced while achieving this task.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Action:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This is the opportunity where you can dive deep on exactly what you did. How did you accomplish the assigned tasks? These imbibe the steps and procedures that you followed to lead the task to its final outcome.&lt;/li&gt;
&lt;li&gt;Think about all the items that you vested your time in and how you personally ensured that the task was achieved on time. Always highlight what you did and not others.&lt;/li&gt;
&lt;li&gt;Be sure to highlight the good qualities you showed in taking those specific actions but never hesitate to mention the misses and learnings you got while accomplishing the task. This helps interviewers understand that you are not afraid of failures and treat them as a learning for future.&lt;/li&gt;
&lt;li&gt;Demonstrate your best traits to the interviewer in the Action phase. If your actions showed strong leadership, amazing communication skills and great dedication, make sure that you let this information flow to your interviewer. Focus on highlighting the abilities that an interviewer would find desirable. Don’t make it explicit by speaking the above traits out. Explain your role and the interactions honestly. Interviewers are smart to pick up hints about traits. &lt;/li&gt;
&lt;li&gt;Candidates usually make a mistake of explicitly talking about how collaborative they are, their dedication levels. Usually interviewers will counter that by asking questions like “Tell me about a time when you had conflict with some teammates/ manager”, “Give me an example where you were not interested in the work given and how did you go about it?”.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Result:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Be introspective here. The result portion of the STAR method is where you demonstrate your achievements and final outcomes.&lt;/li&gt;
&lt;li&gt;Share what the result of the situation was and how you and your actions contributed to that final result.&lt;/li&gt;
&lt;li&gt;What did you achieve? What were the learnings? What were the outcomes of your actions? What were the actions you took? How was the engagement to this outcome? How successful the feature and delivery was?&lt;/li&gt;
&lt;li&gt;If the work is in progress mention its future roadmap and how it would help you create an impact and what status the actions are at.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28j4by2s9m6mfteokbl3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28j4by2s9m6mfteokbl3.png" alt="Situation Task Action Result method" width="800" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  DONT's for STAR Interview Questions:
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;1. Making up answers or being dishonest&lt;/u&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are many a times when for the given situation you cannot think of a single success story, in those situations please let the interview know about it! Interviewer would like an honest person than someone who is bluffing around.&lt;/p&gt;

&lt;p&gt;This doesn't mean that you ask the interviewer to skip the question. You can be pro-active and take the question on yourself by stating your actions had you been in that situation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;2. Going underprepared&lt;/u&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since I have already outlined what each concept mean. Coming up with a story on the spot will lead to lot of mistakes that can pile up and you ending up on critical situations or losing interviewer's interest.&lt;/p&gt;

&lt;p&gt;Be pro-active in doing your homework. Prepare for most of the common questions. Always prepare for both success and failure stories. Keep them simple, concise and pin pointing to the given situation.&lt;/p&gt;

&lt;p&gt;I always recommend preparing for 2-3 success stories and 1-2 failure stories that would enable you to demonstrate a wide variety of traits that an interviewer would be looking for.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;3. Being over-prepared&lt;/u&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Lot of candidates do this mistake. They want their story to seem flawless. Review your answers before you attend the interview, but don’t rehearse them more. Make it like a discussion rather than a narrative. Always remember to not under fit or over fit your brain’s machine learning model with any scenario!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;4. Negative stories?&lt;/u&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Many candidates have this perspective of impressing the interviewers and hence their mental model is: “Why would I tell a story where I had failed miserably and learnt absolutely nothing from the experience?”. Remember that there is a difference between telling success story, failure story and a story where there was absolutely no positive outcome or the lessons learned were negligible.&lt;/p&gt;

&lt;p&gt;Candidates also think: “I would not tell a story that makes me look bad.”. If the interviewer decides to probe into your story and do a dive deep, it's more likely that he/she would reveal something you did not intend to and might make a negative data point.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;5. Story unrelated to the question asked&lt;/u&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Telling a story that is unrelated to the question would demonstrate that you lack focus and attention to detail. This would lead to interviewer considering you as a poor candidate in terms of leadership abilities.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;6. Heroic stories?&lt;/u&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Don't narrate stories where you were the sole hero. Nobody is absolutely perfect and telling a story where you heroically managing everything is impossible, it would be considered as fiction by the interviewer and might lead to negative data points.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common STAR Interview Questions
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Sense of Direction and Judgement :&lt;/u&gt;&lt;/em&gt; These questions help in understanding candidate's quality of judgment, sense of direction and their decision making ability under complicated circumstances.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give me an example about a difficult decision you've made in recent times.&lt;/li&gt;
&lt;li&gt;Describe a time when you had multiple important deliverables and features to finish and how you prioritised them.&lt;/li&gt;
&lt;li&gt;Do you recall an experience where you received conflicting or constructive pieces of feedback on a feature or deliverable? Was it positive or negative? How did you address this feedback?&lt;/li&gt;
&lt;li&gt;Tell me about a time when there was conflict with your team member or team itself, and how you explained this situation to your manager.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Pressure-Handling:&lt;/u&gt;&lt;/em&gt; These questions reveal how well a candidate performs under various types of pressure and situations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Describe a decision you made that was not too mainstream and how you implemented it or got it implemented.&lt;/li&gt;
&lt;li&gt;Tell me about a time when you had to undergo a stressful situation at work and how you handled it.&lt;/li&gt;
&lt;li&gt;Describe a recent situation in which you had to deal with a very upset client. Client can be your customers as well.&lt;/li&gt;
&lt;li&gt;Throw some light on a situation where you disagreed with a superior and how this disagreement was settled.&lt;/li&gt;
&lt;li&gt;Tell me about a time you had to learn something you weren't familiar with and still delivered quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Leadership Abilities:&lt;/u&gt;&lt;/em&gt; These questions reveal a candidate's leadership potential, confidence, long term vision and willingness to take the initiative on projects when they have little or no direction to start with.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tell me about an experience in which you used your leadership abilities.&lt;/li&gt;
&lt;li&gt;Describe a time when you delegated a project to others effectively and got the work done.&lt;/li&gt;
&lt;li&gt;Can you recall a time where you had to give negative feedback to a colleague. How did you express this feedback to him/her?&lt;/li&gt;
&lt;li&gt;Do you have an example when you showed initiative and took the lead.&lt;/li&gt;
&lt;li&gt;Tell me about a time you had a direct report or managed a team that was being recruited to work on other projects without your consent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Self-Awareness:&lt;/u&gt;&lt;/em&gt; These questions give data points about how self aware a candidate is about his/her's strengths and weaknesses.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Describe a time you were able to successfully deliver with a co-worker who might not have personally liked you or the other way round.&lt;/li&gt;
&lt;li&gt;Give me an example of a time when you tried to accomplish something and failed.&lt;/li&gt;
&lt;li&gt;Was there any time you were reprimanded or criticised for your performance.&lt;/li&gt;
&lt;li&gt;Tell me about a project that wasn't going to meet its deadline and how you minimised the consequences of its blast radius.&lt;/li&gt;
&lt;li&gt;Tell me about a time you felt you weren't being listened to or left alone, and how you made you presence or opinion known to your teammates.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary:
&lt;/h2&gt;

&lt;p&gt;I have seen lot of candidates making the common mistakes mentioned above. Avoid those during the interviews and always prepare well for Behavioral interviews using the set of questions provided. They are as important as the technical rounds because they help leaders gather data points regarding how fit you are for the company and what is your growth potential in the long term success. Personally I believe images are better conveyer of information than text. So here is an image from "The Muse" summarising STAR.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzyuh6x0x6539i3zlke8a.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzyuh6x0x6539i3zlke8a.jpeg" alt="Star interview method explained by MUSE" width="628" height="1500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/pulse/becoming-star-using-technique-abhishek-somani/" rel="noopener noreferrer"&gt;Original Post on Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
  </channel>
</rss>
