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 – Go RPC
  • 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-go"
import "net/http"
import "fmt"
import "log"



type HelloService struct{}


type HelloReply struct {
	Message string
}


type HelloArgs struct {
	Who string
}


type Place 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 jason = Place{}
	frappe.Frappe.Db.Get(&jason, `SELECT name, owner FROM "tabUser" limit 1 `)
	fmt.Printf("%#v\n", jason)


	return nil
}

func main() {

	// Register methods for rpc
	frappe.Frappe.Server.RegisterService(new(HelloService), "")

	http.Handle("/rpc", frappe.Frappe.Server)
	http.ListenAndServe("localhost:10000", nil)

}
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"
}

License

MIT

Free Software, Hell Yeah!

GitHub

View Github