据我所知,Go不提供内置的JSON编码/解码器,但这并不意味着您必须从基本的HTTP处理程序开始。1)在服务器管道中使用HttpRequestDecoder、HttpResponseEncoder。2)然后,为JSON编码和解码实现HttpContentDecoder、HttpContentEncoder抽象类,在此处您需要通过提供OneToOneEncoder/Decoder实现来实现newContentDecoder、newContentEncoder方法。您可以使用Google Gson编写OneToOneEncoder/Decoder实现。然后将HttpContentDecoder、HttpContentEncoder实现添加到管道中。有关更多详细信息,请参阅HttpContentDecompressor、HttpContentCompressor源代码。