{"id":26826697,"url":"https://github.com/hslam/funcs","last_synced_at":"2025-04-28T16:49:16.057Z","repository":{"id":55531866,"uuid":"189688971","full_name":"hslam/funcs","owner":"hslam","description":"Function call by its name in Golang","archived":false,"fork":false,"pushed_at":"2022-01-05T10:10:11.000Z","size":67,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-30T11:32:42.538Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hslam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-01T04:09:13.000Z","updated_at":"2025-03-05T03:13:35.000Z","dependencies_parsed_at":"2022-08-15T02:40:35.669Z","dependency_job_id":null,"html_url":"https://github.com/hslam/funcs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Ffuncs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Ffuncs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Ffuncs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Ffuncs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hslam","download_url":"https://codeload.github.com/hslam/funcs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251348741,"owners_count":21575328,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-30T11:30:36.706Z","updated_at":"2025-04-28T16:49:16.037Z","avatar_url":"https://github.com/hslam.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# funcs\n[![GoDoc](https://godoc.org/github.com/hslam/funcs?status.svg)](https://godoc.org/github.com/hslam/funcs)\n[![Build Status](https://github.com/hslam/funcs/workflows/build/badge.svg)](https://github.com/hslam/funcs/actions)\n[![codecov](https://codecov.io/gh/hslam/funcs/branch/master/graph/badge.svg)](https://codecov.io/gh/hslam/funcs)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hslam/funcs?v=d5613e5)](https://goreportcard.com/report/github.com/hslam/funcs)\n[![GitHub release](https://img.shields.io/github/release/hslam/funcs.svg)](https://github.com/hslam/funcs/releases/latest)\n[![LICENSE](https://img.shields.io/github/license/hslam/funcs.svg?style=flat-square)](https://github.com/hslam/funcs/blob/master/LICENSE)\n\nFunction call by its name in golang\n## Get started\n\n### Install\n```\ngo get github.com/hslam/funcs\n```\n### Import\n```\nimport \"github.com/hslam/funcs\"\n```\n### Usage\nFirst create an instance of the funcs:\n```go\nFuncs:=funcs.New()\n```\nThen register your Struct:\n```go\ntype Service struct {\n}\nfunc (s *Service) Method(params ...interface{}) error {\n    //to do\n    return nil\n}\nFuncs.Register(new(Service))\n```\nAnd then call your function by name.\n\nFunction's Name Format : \"StructName.MethodName\"\n```go\nif err := Funcs.Call(\"Service.Method\", params...);err != nil {\n    log.Fatalln(\"Call Service.Method error: \", err)\n}\n```\nLogging.\n```go\nFuncs.SetLog(true)\n```\nif a function has 2 input parameters ,You can get the function's first input parameter and second input parameter.\n```go\nFuncs.GetFuncIn(\"Service.Method\",0)\nFuncs.GetFuncIn(\"Service.Method\",1)\n//and so on\n```\n#### Example\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"github.com/hslam/funcs\"\n\t\"log\"\n)\n\n//ArithRequest is the first input parameter.\ntype ArithRequest struct {\n\tA int\n\tB int\n}\n\n//ArithResponse is the second input parameter.\ntype ArithResponse struct {\n\tQuo int // quotient\n\tRem int // remainder\n}\n\n//Arith is the Service struct.\ntype Arith struct {\n}\n\n//Divide is the Arith's Method.\nfunc (a *Arith) Divide(req *ArithRequest, res *ArithResponse) error {\n\tif req.B == 0 {\n\t\treturn errors.New(\"divide by zero\")\n\t}\n\tres.Quo = req.A / req.B\n\tres.Rem = req.A % req.B\n\treturn nil\n}\n\nfunc main() {\n\tFuncs := funcs.New()\n\tFuncs.SetLog(true)\n\n\t//Funcs.RegisterName(\"Arith\",new(Arith))\n\tFuncs.Register(new(Arith))\n\n\tf := Funcs.GetFunc(\"Arith.Divide\")\n\tfmt.Printf(\"num of args : %d\\n\", f.NumIn())\n\n\t//req := \u0026ArithRequest{A: 9, B: 2}\n\treq := Funcs.GetFuncIn(\"Arith.Divide\", 0).(*ArithRequest)\n\treq.A = 9\n\treq.B = 2\n\n\t//res := \u0026ArithResponse{}\n\tres := Funcs.GetFuncIn(\"Arith.Divide\", 1).(*ArithResponse)\n\n\tif err := Funcs.Call(\"Arith.Divide\", req, res); err != nil {\n\t\tlog.Fatalln(\"Call Arith.Divide error: \", err)\n\t\treturn\n\t}\n\tfmt.Printf(\"%d / %d, quo is %d, rem is %d\\n\", req.A, req.B, res.Quo, res.Rem)\n}\n```\n\n#### Output\n```\n[funcs] 2020/01/09 10:12:19.065121 StructName:Arith,NumMethod:1\n[funcs] 2020/01/09 10:12:19.065246 MethodIndex:0,CallName:Arith.Divide,NumIn:2,NumOut:1\nnum of args : 2\n9 / 2, quo is 4, rem is 1\n```\n### License\nThis package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)\n\n\n### Author\nfuncs was written by Meng Huang.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Ffuncs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhslam%2Ffuncs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Ffuncs/lists"}