Code Monkey home page Code Monkey logo

blaxberry-app-protobuf's Introduction

MyApp ProtoBuf

MyApps' Protocol Buffers & Type Code Generator

Commands

make                    # generate all

make gen-go             # only generate go code based on proto
make gen-ts-onlytypes   # only generate typescript code based on proto

Setup

0. setup environments
  • Goalng
  • Python
  • Node.js
1. install protobuf for using protoc command
# 1. install protobuf compiler
brew install protobuf

# 2. check version
protoc --version
2. install pkg protoc-gen-go for generating Golang code, then add to $PATH
# 1. install pkg
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

# 2. add path
export PATH="$PATH:$(go env GOPATH)/bin" >> ~/.zshrc
source ~/.zshrc

# 3. check pkg's position & version
which protoc-gen-go
protoc-gen-go --version
3. install pkg ts-proto for generating Typescript code
npm install

Usage

TypeScript

1. install pkg inside project
cd <project>
yarn add git+https://github.com/BlaxBerry/myapp_protobuf.git
yarn add -D google-protobuf @types/google-protobuf
2. import type then use
import type { MessageNode, HTMLNode } from "myapp_protobuf/ts/scenario";
import type { ChatBotData } from "myapp_protobuf/ts/chat";
import type { NoteData } from "myapp_protobuf/ts/notes";

Golang

1. get pkg
go get github.com/BlaxBerry/myapp_protobuf/go/scenario@main
2. import pkg then use
import (
    "fmt"

    scenario "github.com/BlaxBerry/myapp_protobuf/go/scenario"
)

var MockMessageNode = &scenario.MessageNode{
	Id:    11,
	Title: "xxx",
	Text:  "yyy",
}

var MockHTMLNode = &scenario.HTMLNode{
	Id:    22,
	Title: "xxx",
	Text:  "yyy",
}

func main() {
    fmt.Println(MockMessageNode.Id)
    fmt.Println(MockMessageNode.Title)
    fmt.Println(MockMessageNode.Text)
}

blaxberry-app-protobuf's People

Contributors

blaxberry333 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.