CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
30
Task/Distributed-programming/Go/distributed-programming-1.go
Normal file
30
Task/Distributed-programming/Go/distributed-programming-1.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/rpc"
|
||||
)
|
||||
|
||||
type TaxComputer float64
|
||||
|
||||
func (taxRate TaxComputer) Tax(x float64, r *float64) error {
|
||||
if x < 0 {
|
||||
return errors.New("Negative values not allowed")
|
||||
}
|
||||
*r = x * float64(taxRate)
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := TaxComputer(.05)
|
||||
rpc.Register(c)
|
||||
rpc.HandleHTTP()
|
||||
listener, err := net.Listen("tcp", ":1234")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
http.Serve(listener, nil)
|
||||
}
|
||||
23
Task/Distributed-programming/Go/distributed-programming-2.go
Normal file
23
Task/Distributed-programming/Go/distributed-programming-2.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/rpc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client, err := rpc.DialHTTP("tcp", "localhost:1234")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
amount := 3.
|
||||
var tax float64
|
||||
err = client.Call("TaxComputer.Tax", amount, &tax)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Tax on %.2f: %.2f\n", amount, tax)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue