github.com/CiscoM31/godata@v1.0.10/example/main.go (about) 1 package example 2 3 /* 4 import ( 5 . "godata" 6 ) 7 */ 8 9 func HelloWorld() { 10 11 } 12 13 func CacheMiddleware() { 14 15 } 16 17 func AuthorizationMiddleware() { 18 19 } 20 21 /* 22 func main() { 23 provider := &MySQLGoDataProvider{ 24 Hostname: "localhost", 25 Port: "3306", 26 Database: "Coffee", 27 Username: "dev", 28 Password: "dev", 29 } 30 31 roaster := provider.ExposeEntity("roaster", "Roaster") 32 roaster.ExposeKey("id", "RoasterID", GoDataInt32) 33 roaster.ExposePrimitive("name", "Name", GoDataString) 34 roaster.ExposePrimitive("location", "Location", GoDataString) 35 roaster.ExposePrimitive("website", "Website", GoDataString) 36 roasterSet := provider.ExposeEntitySet(roaster, "Roasters") 37 38 variety := provider.ExposeEntity("variety", "Variety") 39 variety.ExposeKey("id", "VarietyID", GoDataInt32) 40 variety.ExposePrimitive("name", "Name", GoDataString) 41 varietySet := provider.ExposeEntitySet(variety, "Varieties") 42 43 roastLevel := provider.ExposeEntity("roast_level", "RoastLevel") 44 roastLevel.ExposeKey("id", "RoastLevelID", GoDataInt32) 45 roastLevel.ExposePrimitive("order", "Order", GoDataInt32) 46 roastLevel.ExposePrimitive("name", "Name", GoDataString) 47 roastLevel.ExposePrimitive("qualifier", "Qualifier", GoDataString) 48 roastLevelSet := provider.ExposeEntitySet(roastLevel, "RoastLevels") 49 50 process := provider.ExposeEntity("process", "Process") 51 process.ExposeKey("id", "ProcessID", GoDataInt32) 52 process.ExposePrimitive("name", "Name", GoDataString) 53 processSet := provider.ExposeEntitySet(process, "Processes") 54 55 bean := provider.ExposeEntity("bean", "Bean") 56 bean.ExposeKey("id", "BeanID", GoDataInt32) 57 bean.ExposePrimitive("country", "Country", GoDataString) 58 bean.ExposePrimitive("region", "Region", GoDataString) 59 bean.ExposePrimitive("min_elevation", "MinElevation", GoDataInt32) 60 bean.ExposePrimitive("max_elevation", "MaxElevation", GoDataInt32) 61 beanSet := provider.ExposeEntitySet(bean, "Beans") 62 63 // map many beans to one roaster 64 provider.ExposeManyToOne(bean, roaster, "roaster_id", "Roaster", "Beans") 65 provider.ExposeManyToOne(bean, roastLevel, "roaster_level_id", "RoastLevel", "Beans") 66 provider.ExposeManyToOne(bean, process, "process_id", "Process", "Beans") 67 provider.ExposeManyToMany(bean, variety, "bean_variety_map", "Varieties", "Beans") 68 provider.BindProperty(beanSet, roasterSet, "Roaster", "Roaster", "Beans", "Beans") 69 provider.BindProperty(beanSet, roastLevelSet, "RoastLevel", "RoastLevel", "Beans", "Beans") 70 provider.BindProperty(beanSet, processSet, "Process", "Process", "Beans", "Beans") 71 provider.BindProperty(beanSet, varietySet, "Varieties", "Varieties", "Beans", "Beans") 72 73 service := BuildService(provider) 74 service.ListenAndServe(":8080", "http://localhost") 75 76 //service.AttachMiddleware(CacheMiddleware) 77 //service.AttachMiddleware(AuthorizationMiddleware) 78 //service.BindAction(HelloWorld) 79 //service.BindFunction(HelloWorld) 80 } 81 */