Golang using thrift for authentication and multiplexing

Source: Internet
Author: User

Recently, when combing the company's services, decided to pull the basic components out of service. Because the company has a variety of language development services, decided to use thrift to resolve cross-language communication.

Start a server

Thrift's support for Golang is good, and the official package provides a server base class and a simple service simple_server.go. You can implement the server to do authentication and other statistical operations.
Server defines a tserver interface and some methods, the source code is as follows:

Type Tserver Interface {
Processorfactory () tprocessorfactory//Service
Servertransport () Tservertransport//connection
Inputtransportfactory () ttransportfactory//input
Outputtransportfactory () ttransportfactory//Output
Inputprotocolfactory () Tprotocolfactory//protocol
Outputprotocolfactory () Tprotocolfactory//protocol

Starts the server
Serve () Error
Stops the server. This is optional on a per-implementation basis. Not
All servers are required is cleanly stoppable.
Stop () Error
}
The server method listens, accepts requests, and dispatches the processing. The following is the Simple_server.go server method.

Func (P *tsimpleserver) Serve () error {
ERR: = P.listen ()
If Err!= nil {
return err
}
P.acceptloop ()
return Nil
}
Func (P *tsimpleserver) Acceptloop () error {
for {
Client, Err: = P.servertransport.accept ()
If Err!= nil {
Select {
Case <-p.quit:
return Nil
Default
}
return err
}
If client!= nil {
Go func () {
If err: = p.processrequests (client); Err!= Nil {
Log. PRINTLN ("Error processing request:", err)
}
}()
}
}
}
As long as the implementation of the relevant interface methods, in the method can be related to the identification/statistics processing.

On the problem of multi-multiplexed IDL

Golang Multiplexing is to write service in an IDL file, and Java does not need. This is a little time delay at the beginning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.