mirror of
https://github.com/luxfi/coreth.git
synced 2026-10-30 17:00:51 +00:00
github.com/luxfi/utils is now github.com/luxfi/util. Import paths and the module requirement follow the rename, and the luxutils alias becomes luxutil. The json types cross the evm client boundary, so this also takes luxfi/vm v1.3.18, where those API structs already speak the renamed types. Co-authored-by: Hanzo Dev <[email protected]>
22 lines
755 B
Go
22 lines
755 B
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
package rpc
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/rpc/v2"
|
|
"github.com/luxfi/util/json"
|
|
)
|
|
|
|
// NewHandler returns a new Handler for a service where:
|
|
// - The handler's functionality is defined by [service]
|
|
// [service] should be a gorilla RPC service (see https://www.gorillatoolkit.org/pkg/rpc/v2)
|
|
// - The name of the service is [name]
|
|
func NewHandler(name string, service interface{}) (http.Handler, error) {
|
|
server := rpc.NewServer()
|
|
server.RegisterCodec(json.NewCodec(), "application/json")
|
|
server.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")
|
|
return server, server.RegisterService(service, name)
|
|
}
|