Giter Club home page Giter Club logo

go-chat's Introduction

Goでチャット

image

サーバー起動

go run server.go  # port 8080

フロント起動

cd front
yarn build
yarn start

ブラウザで http://localhost:3000 にアクセス


ざっくり仕様

GraphQLのSubscription機能にて、WebSocketのプッシュ型配信のサンプル。


初回作成時のメモ

go get github.com/99designs/gqlgen      # インストール
go run github.com/99designs/gqlgen init # 初期化(色々自動生成)

初期化後

├── go.mod
├── go.sum
├── gqlgen.yml
├── graph
│   ├── generated
│   │   └── generated.go
│   ├── model
│   │   └── models_gen.go
│   ├── resolver.go           # [3]
│   ├── schema.graphqls       # [1]
│   └── schema.resolvers.go   # [2]
└── server.go
  • [1] のスキーマ定義を好きに書き換える

  • [2] を削除して、generateで再生成

go run github.com/99designs/gqlgen generate  # 再生成
  • [3] のresolver.goのResolverにsubscriberとmutexを定義する
type Resolver struct {
    subscribers map[string]chan<- *model.Message  // 購読者毎のchannelのマップ
    messages    []*model.Message
    mutex       sync.Mutex
}
  • [2] の再生成されたひな形(schema.resolver.go)の、未実装メソッドの中身を実装する。
  • server.goのResolver生成部を修正

go-chat's People

Contributors

umaxyon avatar roomsso 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.