Giter VIP home page Giter VIP logo

frappe-go's Introduction

Frappe-go

Frappe go , Write apis for frappe framework in go

Features

  • Token based authetication
  • RPC

Tech

Frappe-go uses a number of open source projects to work properly:

  • Gorilla RPC - A golang foundation for RPC over HTTP services.
  • Sqlx - General purpose extensions to golang's database/sql.
  • koanf - Simple, lightweight, extensible, configuration management library for Go.
  • Logger - Simple logger for Go programs. Allows custom formats for messages.

And of course Frappe-go itself is open source with a public repository on GitHub.

Installation

Frappe-go requires Go to run.

Install the dependencies and devDependencies and start the server.

package main

import "github.com/shridarpatil/frappe"
import "net/http"
import "fmt"
import "log"



type HelloService struct{}


type HelloReply struct {
	Message string
}


type HelloArgs struct {
	Who string
}


type User struct {
	Name 	string
	Owner	string
}


func (h *HelloService) Say(r *http.Request, args *HelloArgs, reply *HelloReply) error {
	err := frappe.Authorize(r)

	if err != nil{
		return err
	}
	reply.Message = "Hello, " + args.Who + "!"
	log.Printf("args: %v\nreply: %v, \n %v", r, r.Header.Get("Authorization"), frappe.Frappe)

	fmt.Println(frappe.Frappe.Ping())
	var user = User{}
	frappe.Frappe.Db.Get(&user, `SELECT name, owner FROM "tabUser" limit 1 `)
	fmt.Printf("%#v\n", user)


	return nil
}

func main() {

	var config = &frappe.SiteConfig{
		Driver: "postgres",
		DSN: "host=172.17.0.1 port=5432 user=crm password=Gorv71YDDqYaW0kl dbname=crm sslmode=disable",
		EncryptionKey: "sEgBb3h1KKIlGayaGUem65aowNkGQp_3WgWqYnONMa4=",
		SetLogLevel: "INFO",
	}
	var app = frappe.New(
		config,
	)
	app.RegisterService(&HelloService{app}, "")
	http.Handle("/rpc", app.GetServer())
	http.ListenAndServe("localhost:10000", nil)

}

Save above code in main.go and run

go run main.go
localhost:10000/rpc
curl --location --request POST 'http://localhost:10000/rpc' \
--header 'Authorization: token <api_key>:<api_secret>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "method":"HelloService.Say",
    "params":[{"Who":"Shri"}],
    "id":"1"
}'
{
    "result": {
        "Message": "Hello, Shri!"
    },
    "error": null,
    "id": "1"
}

Stats

Python based api took around 100ms on an average image

Golang based api took around less then 10ms on an average image

License

MIT

Free Software, Hell Yeah!

frappe-go's People

Contributors

shridarpatil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.