-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package carbon | ||
|
||
import ( | ||
"go-micro.dev/v4/api/client" | ||
) | ||
|
||
type Carbon interface { | ||
Offset(*OffsetRequest) (*OffsetResponse, error) | ||
} | ||
|
||
func NewCarbonService(token string) *CarbonService { | ||
return &CarbonService{ | ||
client: client.NewClient(&client.Options{ | ||
Token: token, | ||
}), | ||
} | ||
} | ||
|
||
type CarbonService struct { | ||
client *client.Client | ||
} | ||
|
||
// Purchase 1KG (0.001 tonne) of carbon offsets in a single request | ||
func (t *CarbonService) Offset(request *OffsetRequest) (*OffsetResponse, error) { | ||
|
||
rsp := &OffsetResponse{} | ||
return rsp, t.client.Call("carbon", "Offset", request, rsp) | ||
|
||
} | ||
|
||
type OffsetRequest struct { | ||
} | ||
|
||
type OffsetResponse struct { | ||
// the metric used e.g KG or Tonnes | ||
Metric string `json:"metric"` | ||
// projects it was allocated to | ||
Projects []Project `json:"projects"` | ||
// number of tonnes | ||
Tonnes float64 `json:"tonnes"` | ||
// number of units purchased | ||
Units int32 `json:"units"` | ||
} | ||
|
||
type Project struct { | ||
// name of the project | ||
Name string `json:"name"` | ||
// percentage that went to this | ||
Percentage float64 `json:"percentage"` | ||
// amount in tonnes | ||
Tonnes float64 `json:"tonnes"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
DIR=/tmp/services | ||
CDIR=`pwd` | ||
REPO=https://github.com/m3o/m3o-go | ||
|
||
git clone $REPO $DIR | ||
cd $DIR | ||
|
||
# move/delete | ||
rm -rf .git .github go.mod go.sum README.md CNAME Makefile TODO.md LICENSE client cmd examples | ||
mv m3o.go services.go | ||
|
||
# rewrite | ||
grep -r "go.m3o.com" | cut -f 1 -d : | xargs sed -i '[email protected]/[email protected]/v4/api/client@g' | ||
sed -i '[email protected]@go-micro.dev/v4/services@g' services.go | ||
sed -i 's@package m3o@package services@g' services.go | ||
|
||
# sync | ||
cd $CDIR | ||
rsync -avz $DIR/ . | ||
|
||
# cleanup | ||
rm -rf $DIR |