[Solved] Can anybody solve this programming challenge? [closed]

I don’t see anything particularly special about a solution in the Go programming language. For example, // The Love-Letter Mystery // https://www.hackerrank.com/challenges/the-love-letter-mystery package main import ( “bufio” “fmt” “io” “os” “strconv” ) // palindrome returns the minimum number of operations carried out // to convert a word into a palindrome. // A word is a … Read more

[Solved] Go: basic for loop and strconv [closed]

Here’s one way to do it: fmt.Println(“Start of session”) defer fmt.Println(“Room Empty”) for i := 0; i < 6; i++ { s := Student{Name: “Student” + strconv.Itoa(i)} s.Present() defer s.Leave() } fmt.Println(“End of session”) playground example The deferred functions are executed on return from the function in reverse order. 5 solved Go: basic for loop … Read more

[Solved] Is it possible to change the output to be an actual string of characters?

You’re taking *strings when you really only need strings. It’s a simple change to derefernce the pointers you get back from AWS SDK (it uses pointers for everything for nullability): var accountList []string for _, accountId := range result.Accounts { accountList = append(accountList, *accountId.Id) } fmt.Println(accountList) solved Is it possible to change the output to … Read more

[Solved] How I can encode JSON with multiple elements in Go Lang [closed]

Here you are. package main import ( “bytes” “encoding/json” “io” “log” “net/http” “os” “time” ) type Elememt struct { ID int `json:”id”` FirstName string `json:”first_name”` LastName string `json:”last_name”` Time time.Time `json:”time”` Count int `json:”count”` Payout string `json:”payout”` } func main() { elements := []Elememt { { ID: 1, FirstName: “Dmitriy”, LastName: “Groschovskiy”, Time: time.Now(), Count: … Read more

[Solved] Is there any way we can execute a multiple commands in exec.Command?

Since you have used sh -c, the next parameter should be the full command or commands: SystemdockerCommand := exec.Command(“sh”, “-c”, “docker exec 9aa1124 gluster peer detach 192.168.1.1 force”) More generally, as in here: cmd := exec.Command(“/bin/sh”, “-c”, “command1 param1; command2 param2; command3; …”) err := cmd.Run() See this example: sh := os.Getenv(“SHELL”) //fetch default shell … Read more

[Solved] Golang not producing error when decoding “{}” body into struct

{} is just an empty Json object, and it will decode fine to your Operandsstruct, as the struct is not required to have anything in the Operands array. You need to validate that yourself, e.g. err := json.NewDecoder(req.Body).Decode(&operands) if err != nil || len(operands.Values) == 0{ solved Golang not producing error when decoding “{}” body … Read more