Created
April 25, 2017 20:38
-
-
Save cocotton/f136b66126ba64b20c2ba1d2af149bef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example1 | |
import ( | |
"fmt" | |
"..../test" | |
"..../exampleDB" | |
) | |
func main() { | |
// object is of type test.Test for demo purposes | |
object := test.Test{field1:"something", field2: 2} | |
err := validateObject(object) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
err := writeToDB(object) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
fmt.Println("Everything went well") | |
} | |
func validateObject(object test.Test) { | |
if something { | |
return nil | |
} | |
return errors.New("Something went wrong!") | |
} | |
func writeToDB(object test.Test) { | |
err := exampleDB.Write(object) | |
if err != nil { | |
return err | |
} | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example1 | |
import ( | |
"fmt" | |
"..../test" | |
"..../exampleDB" | |
) | |
func main() { | |
// object is of type test.Test for demo purposes | |
object := test.Test{field1:"something", field2: 2} | |
err := validateObject(&object) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
err := writeToDB(&object) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
fmt.Println("Everything went well") | |
} | |
func validateObject(object *test.Test) { | |
if something { | |
return nil | |
} | |
return errors.New("Something went wrong!") | |
} | |
func writeToDB(object *test.Test) { | |
err := exampleDB.Write(object) | |
if err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment