Here I have a struct in golang codegiven below:-
type Schedule struct{
Id int `json:"_id" bson:"_id"`
Day time.Weekday `form:"day" json:"day" bson:"day"`
StartDate int64 `form:"start_date" json:"start_date" bson:"start_date"`
EndDate int64 `form:"end_date" json:"end_date" bson:"end_date"`
StartTime int64 `form:"start_time" json:"start_time" bson:"start_time"`
EndTime int64 `form:"end_time" json:"end_time" bson:"end_time"`
AddedOn int64 `form:"added_on" json:"added_on" bson:"added_on"`
Occurence string `form:"occurence" json:"occurence" bson:"occurence"`
UpdatedOn int64 `form:"updated_on" json:"updated_on" bson:"updated_on"`
}
Here is the route when I hit the route then it will call a function given below:-
Route{"SaveData", "POST", "/schedule", controller.SaveData},
SaveData function:-
func SaveData(c *gin.Context) {
schedule.Day = c.PostForm("day")
fmt.Println(schedule.Day)
}
#Error is :- cannot use c.PostForm("day") (type string) as type time.Weekday in assignment
Type of Weekdays I want to save :-
type Weekday int
const (
Sunday Weekday = iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)
How will I save the weekday in the database using postman. Any help is appreciated. Thank you.