Git Product home page Git Product logo

goma's Introduction

Goma - ごま

Build native mobile apps faster by writing your application logic in GO

With Goma, you can write your mobile app's business logic in GO and reuse them across platforms like IOS and Android. It comes with an embedded database that allows you to save/restore application's objects.

Goma utilizes gomobile to generate platform specific libraries for your apps.

Requirements

  • At least Go 1.5.3 or above
  • Xcode
  • Android Studio or Eclipse

Installation

Get or update Goma with:

go get -u github.com/hemantasapkota/goma

Concepts & Usage

goma.Object - Definition & Construction

Anything that is persitable can be modeled with a Goma object. It can be your app's view, model or both.

A complete goma object should embed goma.Object and implement the goma.DBObject interface.

type Person struct {
  *goma.Object
   Name string `json:"name"`
   Age int `json:"age"`
}

// Implement goma.DBObject interface's Key() method
func (p *Person) Key() string {
  return "sampleApp.Person"
}

goma.Object - Saving to the database

person := &Peron{
 Name: "Jon Panda",
 Age: 20,
}

err := person.Save(person)
if err != nil {
 // do something
}

The object is serialized to JSON and stored in DB.

{"name":"Jon Panda","age":20}

goma.Object - Restoring from the database

person := &Person{}
err := person.Restore(person)

if err != nil {
 // do something
}

Note: For consistency purpose, it's recommended that GOMA object receivers be of pointer type. See this blog post for more details.

Marshaling - Return values from Goma

gomobile has some restrictions as to what types you can return. They are primitives ( int, int64, float float64, string, and bool ) and ( byte array ) []byte.

Goma leverages Go's excellent JSON support. Complex types like structs, arrays, and maps can be easily marshalled into JSON.

Synchronization of Objects

Synchronization is required to ensure multiple goroutine don't modify the same object at the same time. Using mutexes to sycnhronize read/write access to the objects can solve this problem.

type ContainerItem struct {
	Id int `json:"id"`
}

type Container struct {
	*Object
	sync.Mutex

	Children []ContainerItem
}

func (c *Container) Key() string {
	return "goma.container"
}

func (c *Container) AddChild(child ContainerItem) {
	c.Lock()
	defer c.Unlock()

	c.Children = append(c.Children, child)
}

Wiki

Examples

  • Meal Tracker - A simple meal tracker that I use personally

See https://github.com/hemantasapkota/goma-examples

Contribute

We would love for you to contribute to Goma, check the LICENSE file for more info.

Meta

Hemanta Sapkota

Distributed under the MIT license. See LICENSE for more information.

https://github.com/hemantasapkota

goma's People

Contributors

hemantasapkota avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.