---
# System prepended metadata

title: Builder Design Pattern Example in Golang

---

# Builder Design Pattern Example in Golang

 **Code Starts below**

```any=

package main

import (
	"fmt"
	"strconv"
)

// Define User struct
type User struct {
	 firstName string
	 lastName  string
	 city      string
	 gender    string
	 age       int
}

// Greeting 
func (p User) greet() string {
	return "Hello, my name is " + p.firstName + " " + p.lastName + " and I am " + strconv.Itoa(p.age)
}


// getMarried 
func (p *User) getMarried(spouseLastName string) {
	if p.gender == "m" {
		return
	} else {
		p.lastName = spouseLastName
	}
}

func main() {
	User1 := User{"Mohaimin", "Rahman", "Chiitagong", "m", 25}
	User2 := User{"Tasmia", "mehzabin", "Dhaka", "f", 22}

	User1.getMarried("Rahman")

	User2.getMarried("Rahman")
    
    fmt.Println(User1.greet())
	fmt.Println(User2.greet())
}
```