MED Update Users

We need a way to differentiate between standard and premium users. When a new user is created, they need a membership type, and that type will determine the message character limit.

1

Create the Membership struct

Create a new struct called Membership with:

  • A Type string field

  • A MessageCharLimit integer field

2

Embed Membership in User

Update the User struct to embed a Membership.

3

Implement newUser

Complete the newUser function. It should return a new User with all the fields set based on the inputs. If the user is a "premium" member, the MessageCharLimit should be 1000; otherwise it should be 100.

package main

type Membership struct{
	Type               string
	MessageCharLimit   int
}
type User struct {
	Membership
	Name string
}


func newUser(name string, membershipType string) User {
	limit:= 0
	if membershipType == "premium"{
		limit = 1000
	} else {
		limit = 100
	}
	return User{
		Name: name,
		Membership: Membership{
			Type: membershipType,
			MessageCharLimit: limit,
		},
	}
}

Test output: