@@ -13,22 +13,79 @@ This project started as an exercise in doing some recreational programming. I al
1313
1414### usage
1515
16- TODO: write here
16+ The library can be used as follows.
1717
18- The library can be used as follows:
1918
19+ Download it:
2020``` bash
2121go get -u github.com/viveknathani/numero
2222```
2323
24+ Import it:
2425``` go
26+ import " github.com/viveknathani/numero/nparser"
27+ ```
2528
29+ Simple example:
30+ ``` go
31+ expression := " sin(max(2, 3333))"
32+ parser := nparser.New (expression)
33+
34+ result , err := parser.Run ()
35+ ```
36+
37+ Example with variables:
38+ ``` go
39+ expression := " x + y"
40+ parser := New (expression)
41+ parser.SetVariable (" x" , 2 )
42+ parser.SetVariable (" y" , 45 )
43+ result , err := parser.Run ()
2644```
2745
2846The web service can be consumed as follows:
2947
3048``` bash
49+ curl --request POST \
50+ --url https://numero.vivekn.dev/api/v1/eval \
51+ --data ' {
52+ "expression": "x + sin(max(2, 333))",
53+ "variables": {
54+ "x": 100
55+ }
56+ }'
57+ ```
58+
59+ ### documentation
60+
61+ ** Supported functions**
62+ - ` sin `
63+ - ` cos `
64+ - ` tan `
65+ - ` log `
66+ - ` ln `
67+ - ` sqrt `
68+ - ` max `
69+ - ` min `
70+
71+ ** API**
72+
73+ ` POST /api/v1/eval `
74+
75+ Request body parameters (JSON):
76+
77+ - ` expression ` : the expression to evaluate
78+ - ` variables ` : a map of variable names to values
79+
80+ Response body:
3181
82+ ``` json
83+ {
84+ "data" : {
85+ "result" : 99.99117883388611
86+ },
87+ "message" : " success"
88+ }
3289```
3390
3491### contributing
@@ -37,9 +94,9 @@ I am happy to accept pull requests. No hard rules.
3794
3895To set up the project for development, we have the following system requirements:
3996
40- - git
41- - go
42- - make
97+ 1 . git
98+ 2 . go
99+ 3 . make
43100
44101``` bash
45102git clone https://github.com/viveknathani/numero.git
0 commit comments