Anyone know why I am getting syntax error in this file? I have done this in other files for Phone, Email, Person, etc and its fine. But for some reason this file will not take a pointer to a struct.
package interfaces
//Go library for decoding generic map values into native Go structures.
//github.com/mitchellh/mapstructure
//Utilities for Go structs
//github.com/fatih/structs
//TODO: Create new Public repo and Combine required source from each of these two
//repos. We need to same for Struct and interface and Convert to/from each as well
//as the methods for getting / working with the field, values list, etc.
/*
func (s *struct) ToMap() Map{interface}
func (Map{interface}) FromMap() *struct
func (s *struct) FillInterface(m Map{Interface})
func (Map{interface}) FillStruct(s *struct)
..Incomplete ...
*/
/******************************************************************************************
* Base Interface Definition *
******************************************************************************************/
//BaseStruct is only used for building/testing the base interface and will be removed.
type BaseStruct struct {
testInt int
testBool bool
testString string
testByte []byte
testFloat float64
testComplex complex128
}
//BaseInterface contains the support methods required for interacting with a structure
type BaseInterface interface {
//IsStructValid returns true|false if the current struct data is in valid and complete format
IsStructValid() bool
//IsStringValid returns true|false if the passed in string value is in valid and complete format
IsStringValid(s string) bool
//Get returns the current {model}Struct for the interface
Get()
//Set is given all inteface properties and they are assigned to the {model}Struct
Set()
//Parse takes a string and parses it to find and assign the individual struct properties of
//the interfaces parent
Parse(s string)
//Format returns a formatted string for the interface
Format()
//ToMap Converts {model}Struct to a map[string]interface{}
ToMap()
//FromMap converts map[string]interface{} to {model}Struct
FromMap()
//ToJSON converts (model}Struct to a JSON and returns it
ToJSON()
//FromJSON takes a JSON and converts it to {model}Struct
FromJSON()
}
//TestBaseInterface is only used for building/testing the base interface and will be removed.
type TestBaseInterface interface {
*BaseStruct //<-- Syntax Error: unexpected *, expecting method or interface name? WTF?
BaseInterface
}
//IsStructValid returns true|false if the current struct data is in valid and complete format
func (p *BaseStruct) IsStructValid() bool {}
//IsStringValid returns true|false if the passed in string value is in valid and complete format
func (p *BaseStruct) IsStringValid(s string) {}
//Get returns the current {model}Struct for the interface
func (p *BaseStruct) Get() {}
//Set is given all inteface properties and they are assigned to the {model}Struct
func (p *BaseStruct) Set() {}
//Parse takes a string and parses it to find and assign the individual struct properties of
//the interfaces parent
func (p *BaseStruct) Parse(s string) {}
//Format returns a formatted string for the interface
func (p *BaseStruct) Format() {}
//ToMap Converts {model}Struct to a map[string]interface{}
func (p *BaseStruct) ToMap() {}
//FromMap converts map[string]interface{} to {model}Struct
func (p *BaseStruct) FromMap() {}
//ToJSON converts (model}Struct to a JSON and returns it
func (p *BaseStruct) ToJSON() {}
//FromJSON takes a JSON and converts it to {model}Struct
func (p *BaseStruct) FromJSON() {}
//EmailStruct contains a breakdown of a email
//TODO: Update to use/integrate "net/mail" and Address
type EmailStruct struct {
Name string //bob1234
Domain string //gmail.com
}
//Email contains the methods for interacting with Emails (EmailStruct)
type Email interface {
*EmailStruct
intf.BaseInterface
intf.DGraphInterface
intf.BadgerInterface
intf.FileInterface
intf.JSONInterface
intf.ViewInterface
}
And what would be the proper way in Golang for me to have a Struct for the “Properties” and standard interfaces for working with those properties?
Is this the proper way?
package interfaces
//Go library for decoding generic map values into native Go structures.
//github.com/mitchellh/mapstructure
//Utilities for Go structs
//github.com/fatih/structs
//TODO: Create new Public repo and Combine required source from each of these two
//repos. We need to same for Struct and interface and Convert to/from each as well
//as the methods for getting / working with the field, values list, etc.
/*
func (s *struct) ToMap() Map{interface}
func (Map{interface}) FromMap() *struct
func (s *struct) FillInterface(m Map{Interface})
func (Map{interface}) FillStruct(s *struct)
..Incomplete ...
*/
/******************************************************************************************
* Base Interface Definition *
******************************************************************************************/
//BaseStruct is only used for building/testing the base interface and will be removed.
type BaseStruct struct {
testInt int
testBool bool
testString string
testByte []byte
testFloat float64
testComplex complex128
}
//BaseInterface contains the support methods required for interacting with a structure
type BaseInterface interface {
//IsStructValid returns true|false if the current struct data is in valid and complete format
IsStructValid() bool
//IsStringValid returns true|false if the passed in string value is in valid and complete format
IsStringValid(s string) bool
//Get returns the current {model}Struct for the interface
Get()
//Set is given all inteface properties and they are assigned to the {model}Struct
Set()
//Parse takes a string and parses it to find and assign the individual struct properties of
//the interfaces parent
Parse(s string)
//Format returns a formatted string for the interface
Format()
//ToMap Converts {model}Struct to a map[string]interface{}
ToMap()
//FromMap converts map[string]interface{} to {model}Struct
FromMap()
//ToJSON converts (model}Struct to a JSON and returns it
ToJSON()
//FromJSON takes a JSON and converts it to {model}Struct
FromJSON()
}
//TestBaseInterface is only used for building/testing the base interface and will be removed.
type TestBaseInterface struct {
//*BaseStruct properties for this interface
*BaseStruct
//BaseInterface forces implementation of all methods
BaseInterface
}
//IsStructValid returns true|false if the current struct data is in valid and complete format
func (p *BaseStruct) IsStructValid() bool { return false }
//IsStringValid returns true|false if the passed in string value is in valid and complete format
func (p *BaseStruct) IsStringValid(s string) {}
//Get returns the current {model}Struct for the interface
func (p *BaseStruct) Get() {}
//Set is given all inteface properties and they are assigned to the {model}Struct
func (p *BaseStruct) Set() {}
//Parse takes a string and parses it to find and assign the individual struct properties of
//the interfaces parent
func (p *BaseStruct) Parse(s string) {}
//Format returns a formatted string for the interface
func (p *BaseStruct) Format() {}
//ToMap Converts {model}Struct to a map[string]interface{}
func (p *BaseStruct) ToMap() {}
//FromMap converts map[string]interface{} to {model}Struct
func (p *BaseStruct) FromMap() {}
//ToJSON converts (model}Struct to a JSON and returns it
func (p *BaseStruct) ToJSON() {}
//FromJSON takes a JSON and converts it to {model}Struct
func (p *BaseStruct) FromJSON() {}
Its fine I get the idea thanks.
Actually the email one way wrong as well. it was Interface instead of struct like the others. I dont know why it was not showing syntax error but basically BaseTestInterface needs to be a struct that implements a pointer to the struct and whatever interfaces. think I got it now.