Please help me to understand if I use the interface correctly in the code below.
package controllers import ( "../models" ) func GetShedule() { s := models.Shedule{} models.Get(&s) } _
package models import "fmt" type Shedule struct { Specname, Fio, Cab, VP1, VP2, Dayw string } type IGetShedule interface { Get() } func (s *Shedule) Get() { s.Specname = "specname" s.Fio = "fio" s.Cab = "cab" s.VP1 = "vp1" s.VP2 = "vp2" s.Dayw = "dayw" } func Get(s IGetShedule) { s.Get() fmt.Println(s) } I deliberately do not use error handling in order not to complicate this code. Or how would you write it. (this is part of the REST service, the model is called from controllers)
one more option
package controllers import ( "../models" "fmt" ) func Shedule() { s := models.Shedule{} models.SheduleFunc(&s, "get") fmt.Println(s) } __
package models type Shedule struct { Specname, Fio, Cab, VP1, VP2, Dayw string } type IGetShedule interface { Get() Put() } func (s *Shedule) Get() { s.Specname = "specnget" s.Fio = "get" s.Cab = "get" s.VP1 = "get" s.VP2 = "get" s.Dayw = "dget" } func (s *Shedule) Put() { s.Specname = "put" s.Fio = "put" s.Cab = "put" s.VP1 = "put" s.VP2 = "put" s.Dayw = "dput" } func SheduleFunc(s IGetShedule, param string) { switch param { case "get": s.Get() case "put": s.Put() } }