An open API service indexing awesome lists of open source software.

https://github.com/peterhellberg/kop

A small example of using oto for RPC code generation
https://github.com/peterhellberg/kop

Last synced: 12 months ago
JSON representation

A small example of using oto for RPC code generation

Awesome Lists containing this project

README

          

# Köp 📝

[![License MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/peterhellberg/kop#license-mit)

A small example of using [oto](https://github.com/pacedotdev/oto) for RPC code generation in the form of a shopping list CLI.

## Installation

```sh
go install github.com/peterhellberg/kop/cmd/...@latest
```

(This will install two binaries, `kop` and `kop-server`)

## Usage

Run `kop-server` in one terminal (this will by default start a web server on `localhost:12432`)

> [!NOTE]
> If you change the `PORT` for `kop-server`, then you will have to set the `KOP_ENDPOINT` variable accordingly.
>
> (Default is `http://localhost:12432/rpc/`)

Then run `kop Eggs Milk Flour` to create an initial list using the command line interface.

```md
- EGGS
- FLOUR
- MILK
```

> [!IMPORTANT]
> If you speak Swedish, then you will want to `alias köp='kop'` (and if not, then you might want to `alias buy='kop'`)

You can then remove an item from the list by calling `kop no Eggs`

```md
- FLOUR
- MILK
```

If you do not want to use the cli then you can use [cURL](https://curl.se) directly

```sh
curl -d '{}' localhost:12432/rpc/List.Items
```
```json
{
"items": [
"FLOUR",
"MILK"
]
}
```

And even add something else to the list 🍺

```sh
curl -d '{"items": ["Beer"]}' localhost:12432/rpc/List.Add
```
```json
{
"items": [
"BEER",
"FLOUR",
"MILK"
]
}
```

And when you want to start a new list then just run `kop nothing`

## Definitions

The definitions for the RPC service are found in [definitions/definitions.go](definitions/definitions.go)

## Generated

The generated code for the RPC service is in [rpc/gen.go](rpc/gen.go)

## Implementation

The example implementation of the `rpc.List` interface is in [list/list.go](list/list.go)

## Frontend

I added a small HTML frontend (For use from my phone, over [Tailscale](https://tailscale.com/)) using [html/template](https://pkg.go.dev/html/template) and [PicoCSS](https://v2.picocss.com/docs)

It is available on `http://localhost:12432/` when running `kop-server`

## License (MIT)

Copyright (c) 2023 [Peter Hellberg](https://c7.se)

> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.

> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.