How to parse string effectively in a structured manner using Go?

Viewed 60

I have two maps with a key & value like the below. Value is a string here, how can I effectively compare the content(value) of each of these gateways and identify that both are not same? Any structured way to achieve this?

Key: Gateway1

Value:

 | Attribute                     | Value               |
 | ----------------------------- | --------------------|
 | ADDRESS                       |   ipv4:10.1.1.1     |
 | CERT_EXPIRY_LEAD_TIME         |   8                 |
 | CLIENT_CERT_REQ               |   TRUE              |
 | PORT                          |   5000              |
 | SUPPORT_TLS                   |   FALSE             |
 | TLS_DTLS_VERSION              |   1.1               |
 |  TRANSPORT                    |   TCP               |

Key: Gateway2

Value:

 | Attribute                      |Value                    |
 | -----------------------------  |-------------------------|
 | ADDRESS                        |  ipv4:10.1.1.2          |
 | CERT_EXPIRY_LEAD_TIME          |  8                      |
 | CLIENT_CERT_REQ                |  TRUE                   |
 | PORT                           |  4000                   |
 | SUPPORT_TLS                    |  FALSE                  |
 | TLS_DTLS_VERSION               |  1.2                    |
 | TRANSPORT                      |  TCP                    |
1 Answers

For comparing maps you could use DeepEqual.

Here is a sample code (basically taken from here)

/* equal */

func main() { 
    map_1 := map[int]string{   
        1: "One",
        2: "Two",
    }

    map_2 := map[int]string {   
        1: "One",
        2: "Two",
    }     
    res1 := reflect.DeepEqual(map_1, map_2)
    fmt.Println("equal ", res1)
}

/* NOT equal */

func main() { 
    map_1 := map[int]string{   
        3: "Three",
        4: "Four",
    }

    map_2 := map[int]string {   
        1: "One",
        2: "Two",
    }     
    res1 := reflect.DeepEqual(map_1, map_2)
    fmt.Println("Not equal: ", res1)
}
Related