I am trying to use Go parametric functions as its described in the following link Functional options for friendly APIs - however I am getting a type error which I am not sure why.
I am adding my code here for your review:
The error message is:
prog.go:35:18: cannot use port (type func(*Server)) as type func(*Server) error in argument to NewServer
As JimB pointed out, the signatures need to match entirely, including the return value. In your sample code, either have port return error, e.g.:
port := func(srv *Server) error {
srv.Port = 8080
return nil
}
https://play.golang.org/p/LYb846jBD-m
Or remove error from the definition of NewServer:
func NewServer(name string, options ...func(srv *Server)) *Server